ECS Compose-X as an AWS CloudFormation Macro

Deploy to your AWS Account


Lambda Macro





Use with an existing docker-compose file

Say you already have a docker-compose file, and you would like to re-use it as a CloudFormation template. Well you now can, with the CloudFormation macro for ECS Compose-X.

Now, AWS CloudFormation would try to evaluate everything in your current file, which has neither resources, or parameters etc. So this is not a valid CloudFormation template.

For that to work though, all you have to do is add the following lines to your template

  - compose-x

From there, you can deploy your template from the AWS Console or from the CLI, for example, as shown below

aws cloudformation create-stack --template-body file://merged.yml --capabilities ${CAPABILITIES} --stack-name macro-demo


If you have multiple docker-compose files you wish to use, you can either do so via Use with files stored in AWS S3 or simply merge the multiple YAML files together.

Use with files stored in AWS S3

If you have multiple files and through CICD or otherwise, and decided to store them in AWS S3, you can then re-use these files directly from there.

  Name: compose-x
      - s3://
      - s3://
    BucketName: !Sub cfn-templates-${AWS::Region}-${AWS::AccountId}

Customize to your needs or requirements

The provided templates that will allow you to create the Lambda function for the macro and the macro itself, requires an IAM role. Given all the features supported by ECS Compose-X you might want to customize the IAM permissions of the IAM role assigned to the Lambda function.

The current IAM permissions are permissive to gather any information in the account in order to use the Lookup* feature.

Using multi-account lookup

If you wish to use the Lookup feature, this is totally possible. Simply ensure that your docker-compose file indicates which RoleArn to use for the specific lookup and adapt the IAM role of the Lambda function role to allow sts:AssumeRole on that role ARN you are indicating.

CFN Macro Parameters

Parameters syntax reference
ComposeFiles: <list>
BucketName: <str>


The List of files you want to have compiled together in order to deploy your stack


Just like with the CLI, the order in which the files are composed together (first file least priority, last highest priority) the order you list files in ComposeFiles matters in the same way.


The name of the Bucket you have allowed the Lambda Function used for the CFN Macro to upload files to.

Current Limitations

environment files (env_files)

Because of the nature of the syntax requirement for env_files, these are not supported to work with the CFN macro, as the files are not present in the local filesystem.