serverless-application-model icon indicating copy to clipboard operation
serverless-application-model copied to clipboard

Cloudformation randomly fails to create stack

Open Pelto opened this issue 9 years ago • 2 comments

We have a cloudformation stack with the following resources:

  Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub '${AWS::Region}-${AWS::StackName}-bucket'

  Function:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: nodejs6.10
      Handler: index.handler
      CodeUri: .
      Timeout: 60
      MemorySize: 1536
      Policies:
        - Version: '2012-10-17' # Policy Document
          Statement:
            - Effect: Allow
              Action: s3:GetObject*
              Resource: !Sub 'arn:aws:s3:::${AWS::Region}-${AWS::StackName}-bucket/*'
      Events:
        UploadVisitorData:
          Type: S3
          Properties:
            Bucket: !Ref Bucket
            Events: s3:ObjectCreated:*

The creation of the Bucket fails sometimes with the error message: Unable to validate the following destination configurations.

After looking closer to it the best source of information that we have have found has been https://aws.amazon.com/premiumsupport/knowledge-center/unable-validate-destination-s3/.

This seems to be a race condition within the stack outside our control.

Pelto avatar Aug 25 '17 12:08 Pelto

I have pretty much the same issue. I reckon it is because the SAM creates a "AWS::Lambda::Permission" resource automatically to support S3 event notification. It must be created before the act of setting NotificationConfiguration of S3, but sometimes it's created after that, so CF fails with "Unable to validate the following destination configurations". We cannot set dependsOn of S3 to "AWS::Lambda::Permission" as it is created automatically.

kashoory avatar Sep 12 '17 03:09 kashoory

Oh this is fixed now. There is a DependsOn added between the resources to chain them linearly.

sanathkr avatar Jan 12 '18 21:01 sanathkr