AWS – Moving data from one S3 bucket to another with CloudFormation


I’m trying to create a stack with CloudFormation. The stack needs to take some data files from a central S3 bucket and copy them to it’s own “local” bucket.

I’ve written a lambda function to do this, and it works when I run it in the Lambda console with a test event (the test event uses the real central repository and successfully copies the file to a specified repo).

My current CloudFormation script does the following things:

  1. Creates the “local” S3 bucket
  2. Creates a role that the Lambda function can use to access the buckets
  3. Defines the Lambda function to move the specified file to the “local” bucket
  4. Defines some Custom resources to invoke the Lambda function.

It’s at step 4 where it starts to go wrong – the Cloudformation execution seems to freeze here (CREATE_IN_PROGESS). Also, when I try to delete the stack, it seems to just get stuck on DELETE_IN_PROGRESS instead.

Here’s how I’m invoking the Lambda function in the CloudFormation script:

And the Lambda function itself:


Your Custom Resource function needs to send signals back to CloudFormation to indicate completion, status, and any returned values. You will see CREATE_IN_PROGRESS as the status in CloudFormation until you notify it that your function is complete.

The generic way of signaling CloudFormation is to post a response to a pre-signed S3 URL. But there is a cfn-response module to make this easier in Lambda functions. Interestingly, the two examples provided for Lambda-backed Custom Resources use different methods:

Leave a Reply