This repository has been archived by the owner on Feb 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
AWS SAM Deployment
Payton Garland edited this page Apr 5, 2019
·
3 revisions
cloudfront-auth now supports deployment with AWS' Serverless Application Model.
- Install the AWS SAM CLI
- Navigate to your root project directory. In
template.yaml
, modify the CodeUri under the CloudFrontAuthFunction resource. Replace{distribution name}
with the proper value.
CloudFrontAuthFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: distributions/{distribution name}/
Role: !GetAtt LambdaEdgeFunctionRole.Arn
Runtime: nodejs8.10
Handler: index.handler
Timeout: 5
AutoPublishAlias: LIVE
- Run the following sequence of commands. If necessary, specify the AWS profile and/or region with the --region and --profile options.
sam build --use-container
sam package --output-template-file packaged.yaml --s3-bucket bucket-name
sam deploy --template-file packaged.yaml --stack-name stack-name --capabilities CAPABILITY_IAM
For more information on AWS SAM deployment, see the hello-world example
- Configure CloudFront to use the Lambda function upon viewer request:
- Choose the Behaviors tab for your CloudFront distribution, mark the checkbox for the origin, choose Edit
- Under Lambda Function Associations
- Select Viewer Request for the Event Type
- Enter the Lambda ARN value (e.g.
arn:aws:lambda:us-east-1:9999999999:function:my-site-cloudfront-auth:1
) - Save
- It may take Cloudfront up to 20 minutes to fully configure the distribution. You may receive strange errors while the distribution is still updating.
- When fully deployed, your browser will be redirected to your authentication provider as necessary! Enjoy!