Skip to content

Instantly share code, notes, and snippets.

@tobilg
Last active January 9, 2022 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobilg/9d6965350bfee82c9c8efebe7e50f8a3 to your computer and use it in GitHub Desktop.
Save tobilg/9d6965350bfee82c9c8efebe7e50f8a3 to your computer and use it in GitHub Desktop.
{
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com",
"edgelambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}]
},
"Policies": [{
"PolicyName": {
"Fn::Join": [
"-",
[
"backend",
"prd",
"lambda"
]
]
},
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:CreateLogGroup",
"logs:PutLogEvents"
],
"Resource": [{
"Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/backend-prd-edgeCDNAuthorize:*:*"
}]
}
]
}
}],
"Path": "/",
"RoleName": {
"Fn::Join": [
"-",
[
"backend",
"prd",
"edgeCDNAuthorize",
{
"Ref": "AWS::Region"
},
"lambdaRole"
]
]
},
"ManagedPolicyArns": []
}
}
edgeCDNAuthorize:
handler: src/auth/edgeCDNAuthorizer.handler
memorySize: 128
timeout: 5
iamRoleStatements:
# Workaround, see: https://stackoverflow.com/a/37383297/1603357
- Effect: Allow
Action:
- logs:*
Resource: 'arn:aws:logs:*:*:*'
events:
- cloudFront:
eventType: viewer-request
origin:
DomainName: '#{CDNBucket.DomainName}'
OriginPath: ''
Id: S3BucketOrigin
S3OriginConfig:
OriginAccessIdentity:
Fn::Join:
- ''
- - 'origin-access-identity/cloudfront/'
- '#{CDNCloudFrontOriginAccessIdentity}'
behavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: S3BucketOrigin
ForwardedValues:
# See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions-restrictions.html#edge-function-restrictions-all
QueryString: True
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment