By using AWS re:Post, you agree to the Terms of Use
/AWS Cloudformation/

AWS Cloudformation


Hi, I need help in fixing the template. This is snippet of cloudformation template. Its creating the folder in the s3 bucket - datasource as required but Custom::S3CustomResource is stuck in CREATE_IN_PROGRESS. Please let know if there is a solution.

    Type: Custom::S3CustomResource
      ServiceToken: !GetAtt AWSLambdaFunction.Arn
      the_bucket: !Sub 'pe-ftv-${Environment}-dms-s3buckets'
    Type: "AWS::Lambda::Function"
      FunctionName: !Sub 'pe-ftv-${Environment}-lambda'
      Handler: index.handler
      Role: !GetAtt AWSLambdaExecutionRole.Arn
      Timeout: 5
      Runtime: python3.9
        ZipFile: |
          import boto3
          import cfnresponse
          def handler(event, context):
            bucket_name = event['ResourceProperties']['the_bucket']
            s_3 = boto3.client('s3')
            directory_name = "datasource"
            s_3.put_object(Bucket= bucket_name, Key=(directory_name+'/'))
2 Answers

Is this a concrete use case or just an example to test Custom Resources? If this is a concrete use case, can you explain why do you need to create a directory in the bucket? With Amazon S3 folders are just determined implicitly from the keys of the objects you store. If you store an object with key alfa/beta/gamma.txt in an empty bucket when browsing the S3 bucket you will see alfa and beta represented as folders.

Regarding your question, the Cloud Formation stack might get stuck because your customer resource lambda code contains an error and does not return the proper failure message to CloudFormation (see

answered a month ago
  • We need the directory/folder inside the s3 bucket. Is there a way to make cloudformation return the error, reason its doing what is suppose to do, creating the directory.

  • You need to catch possible errors in the lambda function and return a FAILED status. The cfnresponse module does not allow to specify the value of the Reason field, which is defined by the library itself. See

  • Not sure why - we need to add empty dictionary in python string response_data = {} and send in response. cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data)

  • Hi.
    As MassimilianoAWS says, first you need to set cfnresponse for error handling.

    And check the execution log of the Lambda function you created for your custom resource to see why the error is occurring.
    You may be able to get detailed information about the error.
    For example, if the Lambda execution role does not have permission to the target bucket.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions