silvermine / serverless-plugin-cloudfront-lambda-edge

Adds Lambda@Edge support to Serverless
MIT License
296 stars 41 forks source link

deployment failure #59

Closed fusionbeam closed 3 years ago

fusionbeam commented 3 years ago

Hi, I've been following the guide on README.md. I have a basic deployment that fails with this error: "The following resource(s) failed to create: [IamRoleLambdaExecution, WebsiteBucket].".

Here is the serverless.yml:

service: oak

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"

provider:
  name: aws
  runtime: nodejs12.x
  profile: treelet
  region: us-east-1
  stage: ${opt:stage, 'offline'}
  memorySize: 128
  timeout: 3

custom:
  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true
    packager: 'yarn'   # Packager that will be used to package your external modules

  stages:
    - offline
    - production

  objectPrefix: ${self:service}-${self:provider.stage}

plugins:
  - serverless-webpack
  - '@silvermine/serverless-plugin-cloudfront-lambda-edge'

package:
  exclude:
      - 'node_modules/**'

functions:  

  originBroker:    
    name: '${self:custom.objectPrefix}-origin-request'
    handler: src/origin_broker.handler      
    memorySize: 128
    timeout: 1
    lambdaAtEdge:
      distribution: 'WebsiteDistribution'
      eventType: 'origin-request'

resources:
  Resources:
    WebsiteBucket:
       Type: 'AWS::S3::Bucket'
       Properties:
          BucketName: '${self:custom.objectPrefix}'
          AccessControl: 'PublicRead'
          WebsiteConfiguration:
             IndexDocument: 'index.html'
             ErrorDocument: 'error.html'

    ## Specifying the policies to make sure all files inside the Bucket are avaialble to CloudFront
    WebsiteDistribution:
      Type: 'AWS::CloudFront::Distribution'
      Properties:
         DistributionConfig:
            DefaultCacheBehavior:
               TargetOriginId: 'WebsiteBucketOrigin'
               ViewerProtocolPolicy: 'redirect-to-https'
               DefaultTTL: 600 # ten minutes
               MaxTTL: 600 # ten minutes
               Compress: true
               ForwardedValues:
                  QueryString: false
                  Cookies:
                     Forward: 'none'
            DefaultRootObject: 'index.html'
            Enabled: true
            PriceClass: 'PriceClass_100'
            HttpVersion: 'http2'
            ViewerCertificate:
               CloudFrontDefaultCertificate: true
            Origins:
               -
                  Id: 'WebsiteBucketOrigin'
                  DomainName: { 'Fn::GetAtt': [ 'WebsiteBucket', 'DomainName' ] }
                  S3OriginConfig: {}

dependencies: "aws-sdk": "^2.751.0" "serverless": "^1.82.0", "@silvermine/serverless-plugin-cloudfront-lambda-edge":"^2.1.1",


The IAM user for the .aws/credentials has an 'AdministratorAccess' policy.


Anything I am missing?

fusionbeam commented 3 years ago

In case anyone hits the same issue, the fix was to give the bucket a different name: BucketName: '${self:custom.objectPrefix}-website-bucket' perhaps ${self:custom.objectPrefix} alone was conflicting with the Stack name.