getlift / lift

Expanding Serverless Framework beyond functions using the AWS CDK
MIT License
912 stars 111 forks source link

Invalid request provided: AWS::CloudFront::Function: null #329

Closed garritfra closed 1 year ago

garritfra commented 1 year ago

Description

Hi, I'm currently deploying a Laravel application. When trying to integrate static assets using lift, I get the following error:

CREATE_FAILED: websiteRequestFunction9E9EBB7A (AWS::CloudFront::Function)
Resource handler returned message: "Invalid request provided: AWS::CloudFront::Function: null (Service: CloudFront, Status Code: 409, Request ID: 3fb4cd8e-8fa4-4411-801a-2e2aabe17573)" (RequestToken: 95e93590-d1b5-409b-21a5-28a4b2e41d06, HandlerErrorCode: InvalidRequest)

Any hints about what could cause this?

How to Reproduce

service: ...

useDotenv: true

provider:
    name: aws
    # The AWS region in which to deploy (us-east-1 is the default)
    region: eu-central-1
    # Environment variables
    environment:
        APP_ENV: ${sls:stage}
    cfnRole: "<cloudformation role>"
    vpc:
        subnetIds:
          - ...
        securityGroupIds:
          - ...

package:
    # Files and directories to exclude from deployment
    patterns:
        - '!node_modules/**'
        - '!public/storage'
        - '!resources/assets/**'
        - '!storage/**'
        - '!tests/**'
        - '!.ddev/**'

functions:

    # This function runs the Laravel website/API
    web:
        handler: public/index.php
        runtime: php-82-fpm
        timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
        events:
            - httpApi: '*'

    # This function lets us run artisan commands in Lambda
    artisan:
        handler: artisan
        runtime: php-82-console
        timeout: 720 # in seconds
        # Uncomment to also run the scheduler every minute
        #events:
        #    - schedule:
        #          rate: rate(1 minute)
        #          input: '"schedule:run"'

constructs:
    website:
        type: server-side-website
        assets:
            '/js/*': public/js
            '/css/*': public/css
            '/build/*': public/build
            '/vendor/*': public/vendor
            '/favicon.ico': public/favicon.ico
            '/robots.txt': public/robots.txt 

plugins:
    - ./vendor/bref/bref
    - serverless-dotenv-plugin
    - serverless-lift

Additional Information

Versions of the serverless plugins:

        "serverless-dotenv-plugin": "^6.0.0",
        "serverless-lift": "^1.25.1",

And serverless itself:

Framework Core: 3.30.1 (local) 3.30.1 (global)
Plugin: 6.2.3
SDK: 4.3.2
garritfra commented 1 year ago

After way too much trial and error I finally identified the problem.

The creation CloudFormation::Function fails with a cryptic error (Invalid request provided: AWS::CloudFront::Function: null), but the status code of 409 (Conflict) gives it away. There was already a CloudFormation Function. Deleting it solved the issue.

ktwbc commented 1 year ago

I ran into this because I had two monorepos forked from the same source and both had "app" as the construct name for the website (as is in the example) and that was creating the same Logical ID on both stacks used for the function. Very confusing and not obvious behavior.

  constructs: {
    app: {
      type: 'single-page-app',
      path: '../app/dist'
    }
  },