aghadiry / serverless-cloudfront-invalidate

Serverless plugin that allows you to invalidate Cloudfront Cache
MIT License
29 stars 22 forks source link

Failing on initial deploy #39

Open tstackhouse opened 1 year ago

tstackhouse commented 1 year ago

On a freshly deployed stack, this plugin seems to be throwing a fit:

 Deploying <app> to stage <fresh-deploy> (us-east-1)
Using deployment bucket '<deployment-bucket>'
DistributionIdKey: CloudFrontDistributionOutput
{"code":"AWS_CLOUD_FRONT_CREATE_INVALIDATION_MISSING_REQUIRED_PARAMETER","providerError":{"message":"Missing required key 'DistributionId' in params","code":"MissingRequiredParameter","time":"2023-05-15T19:36:01.821Z"},"providerErrorCodeExtension":"MISSING_REQUIRED_PARAMETER"}
CloudfrontInvalidate: Invalidation failed
Failed to get DistributionId from stack output. Please check your serverless template.

Relevant parts of my serverless.yml:

service: <app>
frameworkVersion: '3.30.1'

provider:
  name: aws
  runtime: nodejs16.x

plugins:
  - serverless-cloudfront-invalidate # This plugins is the last one listed

custom:
  cloudfrontInvalidate:
    - distributionIdKey: 'CloudFrontDistributionOutput'
      autoInvalidate: true
      items:
        - '/*'
        - '/'

resources:
  Resources:
    CloudFrontDistribution:
      Type: AWS::CloudFront::Distribution

  Outputs:
    CloudFrontDistributionOutput:
      Value:
        'Ref': CloudFrontDistribution

I get the feeling that this is a race condition or something else caused by the plugin attempting to run before the CloudFront distribution is actually created, because it appears that running the deploy again results in a success.