Skip to content
This repository was archived by the owner on Jun 14, 2020. It is now read-only.

Commit 4077e39

Browse files
committed
Another attempt at fixing 'access denied' when pushing to SQS from Lambda // #49
1 parent 4d98117 commit 4077e39

9 files changed

+58
-10
lines changed

aws/apex-up/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ This sets up AWS IAM for being able to deploy our web app on Up.
55
> for more details.
66
> * [apex-up-policy.json](apex-up-policy.json) comes from
77
> [here](https://up.docs.apex.sh/#aws_credentials.iam_policy_for_up_cli).
8+
> * [apex-up-lambda-policy.json](apex-up-lambda-policy.json) is an extended version of the inline
9+
> policy assigned originally to the default IAM role `ghuser-function` created by Up and
10+
> assumed/impersonated by our Lambda function. We have added for example permissions to push to
11+
> SQS.
12+
> * [apex-up-lambda-trust-relationship.json](apex-up-lambda-trust-relationship.json) is the
13+
> [trust relationship policy document](https://stackoverflow.com/a/34188307/1855917) assigned
14+
> originally to `ghuser-function`.
815
916
```bash
1017
$ export AWS_ACCOUNT_ID=123456789012
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Action": [
6+
"logs:CreateLogGroup",
7+
"logs:CreateLogStream",
8+
"logs:PutLogEvents",
9+
"ssm:GetParametersByPath",
10+
"ec2:CreateNetworkInterface",
11+
"ec2:DescribeNetworkInterfaces",
12+
"ec2:DeleteNetworkInterface",
13+
14+
"sqs:*"
15+
],
16+
"Effect": "Allow",
17+
"Resource": "*"
18+
}
19+
]
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Effect": "Allow",
6+
"Principal": {
7+
"Service": "apigateway.amazonaws.com"
8+
},
9+
"Action": "sts:AssumeRole"
10+
},
11+
{
12+
"Effect": "Allow",
13+
"Principal": {
14+
"Service": "lambda.amazonaws.com"
15+
},
16+
"Action": "sts:AssumeRole"
17+
}
18+
]
19+
}

aws/apex-up/setup_iam_for_apex_up.sh

+7
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ set -xe
44
source ../impl/iam.sh
55

66
createPolicyAndGroupForUser apex-up up.docs.apex.sh apex-up-policy.json apex-up
7+
8+
aws iam create-policy --policy-name apex-up-lambda \
9+
--policy-document "file://./apex-up-lambda-policy.json"
10+
aws iam create-role --role-name apex-up-lambda \
11+
--assume-role-policy-document "file://./apex-up-lambda-trust-relationship.json"
12+
aws iam attach-role-policy --role-name apex-up-lambda \
13+
--policy-arn "arn:aws:iam::$AWS_ACCOUNT_ID:policy/apex-up-lambda"

reframe/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/dist/
2+
/up.json

reframe/genUpJson.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
envsubst < up.json.template > up.json

reframe/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"local": "reframe start",
1616
"cleanmod": "rm -rf node_modules/ && npm install",
1717
"warmup": "curl -s --output /dev/null https://ghuser.io && curl -s --output /dev/null https://www.ghuser.io",
18-
"deploy": "reframe build && rm -rf dist/previous/ && ./populateUpJson.sh && ./up && ./up production && ./up stack status && npm run warmup",
18+
"deploy": "reframe build && rm -rf dist/previous/ && ./genUpJson.sh && ./up && ./up production && ./up stack status && npm run warmup",
1919
"_comment": "staging and production logs:",
2020
"logs": "./up logs --since=20m"
2121
},

reframe/populateUpJson.sh

-4
This file was deleted.

reframe/up.json renamed to reframe/up.json.template

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"us-east-1"
77
],
88
"lambda": {
9+
"role": "arn:aws:iam::$AWS_ACCOUNT_ID:role/apex-up-lambda",
910
"memory": 256
1011
},
1112
"stages": {
@@ -22,10 +23,6 @@
2223
"COOKIE_ENCRYPTION_PASSWORD": "$COOKIE_ENCRYPTION_PASSWORD",
2324
"GITHUB_CLIENT_ID": "$GITHUB_CLIENT_ID",
2425
"GITHUB_CLIENT_SECRET": "$GITHUB_CLIENT_SECRET",
25-
"SENTRY_DNS": "$SENTRY_DNS",
26-
27-
"comment__": "Underscore at the end is a temporary fix for the build. Without it Up fails with https://github.com/apex/apex/issues/829",
28-
"AWS_ACCESS_KEY_ID_": "$AWS_ACCESS_KEY_ID",
29-
"AWS_SECRET_ACCESS_KEY_": "$AWS_SECRET_ACCESS_KEY"
26+
"SENTRY_DNS": "$SENTRY_DNS"
3027
}
3128
}

0 commit comments

Comments
 (0)