Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

AWS SAM Deployment

Payton Garland edited this page Apr 5, 2019 · 3 revisions

cloudfront-auth now supports deployment with AWS' Serverless Application Model.

  1. Install the AWS SAM CLI
  2. 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
  1. Run the following sequence of commands. If necessary, specify the AWS profile and/or region with the --region and --profile options.
    1. sam build --use-container
    2. sam package --output-template-file packaged.yaml --s3-bucket bucket-name
    3. 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

  1. Configure CloudFront to use the Lambda function upon viewer request:
    1. Choose the Behaviors tab for your CloudFront distribution, mark the checkbox for the origin, choose Edit alt text
    2. 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) alt text
      • Save
    3. It may take Cloudfront up to 20 minutes to fully configure the distribution. You may receive strange errors while the distribution is still updating.
    4. When fully deployed, your browser will be redirected to your authentication provider as necessary! Enjoy!
Clone this wiki locally