5

I am using CodeDeploy integrated into CodePipeline. I am trying to deploy an image from ecr to ecs.

The whole infrastructure is built with CloudFormation.

The template for the Pipeline deployment group:

ApplicationName=cls.application.ApplicationName,
DeploymentGroupName='DeploymentGroup',
DeploymentConfigName='CodeDeployDefault.ECSAllAtOnce',
ServiceRoleArn=GetAtt(cls.role, 'Arn'),
AutoRollbackConfiguration={
    'enabled': True,
    'events': ['DEPLOYMENT_FAILURE', 'DEPLOYMENT_STOP_ON_ALARM', 'DEPLOYMENT_STOP_ON_REQUEST']
},
DeploymentStyle={
    'deploymentType': 'BLUE_GREEN',
    'deploymentOption': 'WITH_TRAFFIC_CONTROL'
},
BlueGreenDeploymentConfiguration={
    'terminateBlueInstancesOnDeploymentSuccess': {
        'action': 'TERMINATE',
        'terminationWaitTimeInMinutes': 5
    },
    'deploymentReadyOption': {
        'actionOnTimeout': 'CONTINUE_DEPLOYMENT',
    },
},
LoadBalancerInfo= <Some irrelevant config>
EcsServices=[
    {
        'serviceName': 'WordpressService',
        'clusterName': 'WordpressCluster'
    },
]

So far - the configuration seems pretty straight-forward. The configuration for the pipeline itself contains 2 stages:

ArtifactStore=ArtifactStore(
    Location='SomeS3Location',
    Type='S3'
),
Name='WordpressPipeline',
RoleArn=GetAtt(cls.role, 'Arn'),
Stages=[
    Stages(
        Name='SourceStage',
        Actions=[
            Actions(
                Name='SourceAction',
                ActionTypeId=ActionTypeId(
                    Category='Source',
                    Owner='AWS',
                    Version='1',
                    Provider='ECR'
                ),
                OutputArtifacts=[
                    OutputArtifacts(
                        Name='SourceOutput'
                    )
                ],
                Configuration={
                    'RepositoryName':'SomeECR'
                },
                RunOrder='1'
            )
        ]
    ),
    Stages(
        Name='DeployStage',
        Actions=[
            Actions(
                Name='DeployAction',
                ActionTypeId=ActionTypeId(
                    Category='Deploy',
                    Owner='AWS',
                    Version='1',
                    Provider='CodeDeploy'
                ),
                InputArtifacts=[
                    InputArtifacts(
                        Name='SourceOutput'
                    )
                ],
                Configuration={
                    'ApplicationName': 'MyApp',
                    'DeploymentGroupName': 'MyGroup'
                },
                RunOrder='1'
            )
        ]
    )
]

P.S. dont mind the syntax. I am using Troposphere to create CloudFormation templates.

Firstly, the CloudFormation template ran successfully.

Secondly, Sourcing from ECR succeed.

Thirdly, deployment fails with message:

The deployment specifies that the revision is a null file, but the revision provided is a zip file.

Do you have any idea where might be the problem?

Thank you in advance.

Laimonas Sutkus
  • 3,247
  • 2
  • 26
  • 47

2 Answers2

3

Found out where the issue was. The deploy provider was CodeDeploy which is not valid for my blue/green deployments. I hade to specify CodeDeployToECS instead. Also, I had to change required environment parameters. Here is a nice tutorial by AWS: https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-ecs-ecr-codedeploy.html#tutorials-ecs-ecr-codedeploy-pipeline

Laimonas Sutkus
  • 3,247
  • 2
  • 26
  • 47
  • 1
    thanks for posting this answer, i had the same problem and I found it incredibly frustrating to debug. – Ryan Quinn Nov 15 '19 at 20:34
  • This is perhaps new since this original answer was accepted, but the CodeDeploy provider **can indeed** do blue/green deployments to ECS, provided the AWS Deployment Group is set up and the Task Definition, ECS Service (configured with DeploymentController = CODE_DEPLOY), ECS Cluster, etc. are all set up. See my answer for details. – matt forsythe Jun 07 '23 at 06:09
0

I got this issue in two separate situations as I struggled to set up the exact same arrangement (CodePipeline deploying ECR image to ECS cluster). The first time was because I referenced the ECR image artifact as the input artifact to the CodeDeploy provider, when in fact it should have been an AppSpec file.

The second time was because I was trying to source the AppSpec file from an S3 bucket that was a bare yaml file, rather than having the file stored in a zip file.

Once I finally got things set up to the point where manual deployments were working successfully by clicking the "Create Deployment" button in the UI for the Deployment Group, then all I had to do was put the AppSpec file into a zip file (this was the piece I was missing), source it into the pipeline, and then reference it (not the ECR image) as my input artifact in the CodeDeploy provider.

matt forsythe
  • 3,863
  • 1
  • 19
  • 29