| 
 | 1 | +service: ${self:provider.environment.WEBSITE_S3_BUCKET_NAME}  | 
 | 2 | + | 
 | 3 | +provider:  | 
 | 4 | +  name: aws  | 
 | 5 | +  runtime: nodejs6.10  | 
 | 6 | + | 
 | 7 | +  stage: dev  | 
 | 8 | +  region: us-east-1 # Lambda@Edge function must be us-east-1  | 
 | 9 | + | 
 | 10 | +  environment:  | 
 | 11 | +    WEBSITE_S3_BUCKET_NAME: ${env:WEBSITE_S3_BUCKET_NAME, 'sls-static-basic'}  | 
 | 12 | + | 
 | 13 | +plugins:  | 
 | 14 | +  - serverless-s3-sync  | 
 | 15 | +  - serverless-plugin-cloudfront-lambda-edge  | 
 | 16 | + | 
 | 17 | +custom:  | 
 | 18 | +  s3Sync:  | 
 | 19 | +    - bucketName: ${self:provider.environment.WEBSITE_S3_BUCKET_NAME}  | 
 | 20 | +      localDir: src  | 
 | 21 | + | 
 | 22 | +functions:  | 
 | 23 | +  basicAuth:  | 
 | 24 | +    name: '${self:provider.environment.WEBSITE_S3_BUCKET_NAME}-viewer-request'  | 
 | 25 | +    handler: handler.basicAuth  | 
 | 26 | +    memorySize: 128  | 
 | 27 | +    timeout: 1  | 
 | 28 | +    lambdaAtEdge:  | 
 | 29 | +      distribution: WebsiteDistribution  | 
 | 30 | +      eventType: 'viewer-request'  | 
 | 31 | + | 
 | 32 | +resources:  | 
 | 33 | +  Resources:  | 
 | 34 | +    WebsiteBucket:  | 
 | 35 | +      Type: AWS::S3::Bucket  | 
 | 36 | +      Properties:  | 
 | 37 | +        BucketName: ${self:provider.environment.WEBSITE_S3_BUCKET_NAME}  | 
 | 38 | +        AccessControl: Private  | 
 | 39 | +        WebsiteConfiguration:  | 
 | 40 | +          IndexDocument: index.html  | 
 | 41 | +          ErrorDocument: error.html  | 
 | 42 | +    WebsiteBucketPolicy:  | 
 | 43 | +      Type: AWS::S3::BucketPolicy  | 
 | 44 | +      Properties:  | 
 | 45 | +        Bucket: { Ref: WebsiteBucket }  | 
 | 46 | +        PolicyDocument:  | 
 | 47 | +          Statement:  | 
 | 48 | +            -  | 
 | 49 | +              Action:  | 
 | 50 | +                - "s3:GetObject"  | 
 | 51 | +              Effect: Allow  | 
 | 52 | +              Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { Ref : WebsiteBucket }, "/*" ] ]  }  | 
 | 53 | +              Principal:  | 
 | 54 | +                AWS: { "Fn::Join" : [" ", ["arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity", { Ref: WebsiteOriginAccessIdentity } ] ] }  | 
 | 55 | +    WebsiteOriginAccessIdentity:  | 
 | 56 | +      Type: AWS::CloudFront::CloudFrontOriginAccessIdentity  | 
 | 57 | +      Properties:  | 
 | 58 | +        CloudFrontOriginAccessIdentityConfig:  | 
 | 59 | +          Comment: "CloudFrontOriginAccessIdentity for ${self:service}-${self:provider.stage}"  | 
 | 60 | +    WebsiteDistribution:  | 
 | 61 | +      Type: AWS::CloudFront::Distribution  | 
 | 62 | +      Properties:  | 
 | 63 | +        DistributionConfig:  | 
 | 64 | +          DefaultCacheBehavior:  | 
 | 65 | +            AllowedMethods: [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]  | 
 | 66 | +            CachedMethods:  [ "GET", "HEAD", "OPTIONS" ]  | 
 | 67 | +            TargetOriginId: WebsiteBucketOrigin  | 
 | 68 | +            ViewerProtocolPolicy: redirect-to-https  | 
 | 69 | +            DefaultTTL: 0  | 
 | 70 | +            MaxTTL: 0  | 
 | 71 | +            MinTTL: 0  | 
 | 72 | +            Compress: true  | 
 | 73 | +            ForwardedValues:  | 
 | 74 | +              QueryString: true  | 
 | 75 | +              Cookies:  | 
 | 76 | +                Forward: 'all'  | 
 | 77 | +          CustomErrorResponses:  | 
 | 78 | +            -  | 
 | 79 | +              ErrorCode: '403'  | 
 | 80 | +              ErrorCachingMinTTL: 1  | 
 | 81 | +            -  | 
 | 82 | +              ErrorCode: '404'  | 
 | 83 | +              ErrorCachingMinTTL: 1  | 
 | 84 | +            -  | 
 | 85 | +              ErrorCode: '500'  | 
 | 86 | +              ErrorCachingMinTTL: 1  | 
 | 87 | +            -  | 
 | 88 | +              ErrorCode: '502'  | 
 | 89 | +              ErrorCachingMinTTL: 1  | 
 | 90 | +            -  | 
 | 91 | +              ErrorCode: '503'  | 
 | 92 | +              ErrorCachingMinTTL: 1  | 
 | 93 | +            -  | 
 | 94 | +              ErrorCode: '504'  | 
 | 95 | +              ErrorCachingMinTTL: 1  | 
 | 96 | +          DefaultRootObject: 'index.html'  | 
 | 97 | +          Enabled: true  | 
 | 98 | +          PriceClass: 'PriceClass_100'  | 
 | 99 | +          HttpVersion: 'http2'  | 
 | 100 | +          ViewerCertificate:  | 
 | 101 | +            CloudFrontDefaultCertificate: true  | 
 | 102 | +          Origins:  | 
 | 103 | +            -  | 
 | 104 | +              Id: 'WebsiteBucketOrigin'  | 
 | 105 | +              DomainName: { 'Fn::GetAtt': [ WebsiteBucket, DomainName ] }  | 
 | 106 | +              S3OriginConfig:  | 
 | 107 | +                OriginAccessIdentity: { "Fn::Join" : ["", ["origin-access-identity/cloudfront/", { Ref: WebsiteOriginAccessIdentity } ] ]  }  | 
 | 108 | +  Outputs:  | 
 | 109 | +    WebsiteURL:  | 
 | 110 | +      Value: { "Fn::Join" : ["", ["https://", { "Fn::GetAtt" : [ WebsiteDistribution, DomainName ] } ] ] }  | 
 | 111 | +      Description: "URL for website via CloudFront"  | 
0 commit comments