Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

docs: give the media function a first-time AWS setup that is one user and one bucket

kashorin2e16a5e6ea8c
diff --git a/services/media-lambda/README.md b/services/media-lambda/README.md
index 21da20b1..3a7ee19b 100644
--- a/services/media-lambda/README.md
+++ b/services/media-lambda/README.md
@@ -22,6 +22,46 @@ Artifact it cannot read.
**An execution role** that can read and write the Artifact prefix in that
bucket, and write CloudWatch Logs. Nothing else.
+## First-time AWS setup
+
+One IAM user and one bucket. Everything else — the ECR repository, the function,
+and (for the renderer) its whole stack — is created by the scripts that need it.
+
+The policies under `iam/` are templates: replace `ACCOUNT_ID`, `REGION` and
+`BUCKET`. They are scoped to named resources rather than `*`, so a mistake
+cannot reach the rest of the account.
+
+```bash
+export AWS_REGION=us-east-1
+export AWS_ACCOUNT_ID=123456789012
+export NARRATAGE_MEDIA_BUCKET=your-artifact-bucket
+
+# 1. The bucket the Build and the function share.
+aws s3api create-bucket --bucket "$NARRATAGE_MEDIA_BUCKET" --region "$AWS_REGION"
+aws s3api put-public-access-block --bucket "$NARRATAGE_MEDIA_BUCKET" \
+ --public-access-block-configuration \
+ BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
+
+# 2. The role the function runs as. It can read and write Artifacts, and say
+# what happened. Nothing else.
+sed -e "s/ACCOUNT_ID/$AWS_ACCOUNT_ID/g" -e "s/REGION/$AWS_REGION/g" \
+ -e "s/BUCKET/$NARRATAGE_MEDIA_BUCKET/g" iam/execution.json > /tmp/execution.json
+aws iam create-role --role-name NarratageMediaExecution \
+ --assume-role-policy-document file://iam/execution-trust.json
+aws iam put-role-policy --role-name NarratageMediaExecution \
+ --policy-name NarratageMediaExecution --policy-document file:///tmp/execution.json
+
+# 3. The user that publishes. Attach iam/publisher.json with the same
+# substitutions, then configure its keys as a named profile — never in this
+# repository, and never assembled by hand in code.
+aws configure --profile narratage
+```
+
+Credentials reach the SDK through its default chain. That is deliberate: a
+managed runtime injects `AWS_SESSION_TOKEN`, and code that rebuilds a
+credential object from an id and a secret drops it, so every request fails
+`InvalidAccessKeyId`.
+
## Deploying it
```bash
diff --git a/services/media-lambda/iam/execution-trust.json b/services/media-lambda/iam/execution-trust.json
new file mode 100644
index 00000000..75acf2c0
--- /dev/null
+++ b/services/media-lambda/iam/execution-trust.json
@@ -0,0 +1,10 @@
+{
+ "Version": "2012-10-17",
+ "Statement": [
+ {
+ "Effect": "Allow",
+ "Principal": { "Service": "lambda.amazonaws.com" },
+ "Action": "sts:AssumeRole"
+ }
+ ]
+}
diff --git a/services/media-lambda/iam/execution.json b/services/media-lambda/iam/execution.json
new file mode 100644
index 00000000..d3c29156
--- /dev/null
+++ b/services/media-lambda/iam/execution.json
@@ -0,0 +1,17 @@
+{
+ "Version": "2012-10-17",
+ "Statement": [
+ {
+ "Sid": "ReadSourcesAndWriteResults",
+ "Effect": "Allow",
+ "Action": ["s3:GetObject", "s3:PutObject"],
+ "Resource": "arn:aws:s3:::BUCKET/*"
+ },
+ {
+ "Sid": "SayWhatHappened",
+ "Effect": "Allow",
+ "Action": ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"],
+ "Resource": "arn:aws:logs:REGION:ACCOUNT_ID:*"
+ }
+ ]
+}
diff --git a/services/media-lambda/iam/publisher.json b/services/media-lambda/iam/publisher.json
new file mode 100644
index 00000000..bbe2b732
--- /dev/null
+++ b/services/media-lambda/iam/publisher.json
@@ -0,0 +1,55 @@
+{
+ "Version": "2012-10-17",
+ "Statement": [
+ {
+ "Sid": "PushTheImage",
+ "Effect": "Allow",
+ "Action": [
+ "ecr:BatchCheckLayerAvailability",
+ "ecr:CompleteLayerUpload",
+ "ecr:CreateRepository",
+ "ecr:DescribeImages",
+ "ecr:DescribeRepositories",
+ "ecr:InitiateLayerUpload",
+ "ecr:PutImage",
+ "ecr:UploadLayerPart"
+ ],
+ "Resource": "arn:aws:ecr:REGION:ACCOUNT_ID:repository/narratage-media"
+ },
+ {
+ "Sid": "EcrLoginIsAccountWide",
+ "Effect": "Allow",
+ "Action": ["ecr:GetAuthorizationToken"],
+ "Resource": "*"
+ },
+ {
+ "Sid": "PublishTheFunction",
+ "Effect": "Allow",
+ "Action": [
+ "lambda:CreateFunction",
+ "lambda:GetFunction",
+ "lambda:GetFunctionConfiguration",
+ "lambda:InvokeFunction",
+ "lambda:PublishVersion",
+ "lambda:UpdateFunctionCode",
+ "lambda:UpdateFunctionConfiguration"
+ ],
+ "Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:narratage-media*"
+ },
+ {
+ "Sid": "HandTheExecutionRoleToTheFunction",
+ "Effect": "Allow",
+ "Action": ["iam:PassRole"],
+ "Resource": "arn:aws:iam::ACCOUNT_ID:role/NarratageMediaExecution"
+ },
+ {
+ "Sid": "TheArtifactStore",
+ "Effect": "Allow",
+ "Action": ["s3:GetObject", "s3:PutObject", "s3:ListBucket", "s3:DeleteObject"],
+ "Resource": [
+ "arn:aws:s3:::BUCKET",
+ "arn:aws:s3:::BUCKET/*"
+ ]
+ }
+ ]
+}