Search code examples
aws-cloudformationamazon-elastic-beanstalkamazon-ecs

Specify ECR image instead of S3 file in Cloud Formation Elastic Beanstalk template


I'd like to reference an EC2 Container Registry image in the Elastic Beanstalk section of my Cloud Formation template. The sample file references an S3 bucket for the source bundle:

"applicationVersion": {
  "Type": "AWS::ElasticBeanstalk::ApplicationVersion",
  "Properties": {
    "ApplicationName": { "Ref": "application" },
    "SourceBundle": {
      "S3Bucket": { "Fn::Join": [ "-", [ "elasticbeanstalk-samples", { "Ref": "AWS::Region" } ] ] },
      "S3Key": "php-sample.zip"
    }
  }
}

Is there any way to reference an EC2 Container Registry image instead? Something like what is available in the EC2 Container Service TaskDefinition?


Solution

  • Upload a Dockerrun file to S3 in order to do this. Here's an example dockerrun:

    {
      "AWSEBDockerrunVersion": "1",
      "Authentication": {
        "Bucket": "my-bucket",
        "Key": "mydockercfg"
      },
      "Image": {
        "Name": "quay.io/johndoe/private-image",
        "Update": "true"
      },
      "Ports": [
        {
          "ContainerPort": "8080:80"
        }
      ],
      "Volumes": [
        {
          "HostDirectory": "/var/app/mydb",
          "ContainerDirectory": "/etc/mysql"
        }
      ],
      "Logging": "/var/log/nginx"
    }
    

    Use this file as the s3 key. More info is available here.