AWS ECS deploy not updating new revision and not updating latest image from ecr
Asked by Venkat P:

Hi Team,

We are using below script to deploying the AWS ECS, it's trying to updating ecs service but not updating and it's sitting old revision and ecr latest image also not updating can some one suggest how to deploy aws ecs using bitbucket pipeline.  

Mentioned below yml file.

image: python:3.7.4-alpine3.10  
pipelines:  
tags:  
ecr-release-\*:  
- step:  
name: Build and pushing the Docker Image  
services:  
- docker  
caches:  
- pip  
script:  
- pip3 install awscli  
- IMAGE="709724358365.dkr.ecr.ap-south-1.amazonaws.com/testrepo"  
- TAG=V1.1.05  
- aws configure set aws_access_key_id $AWS_ACCESS_KEY  
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY  
- aws configure set AWS_DEFAULT_REGION $AWS_REGION  
- eval $(aws ecr get-login --no-include-email --region ap-south-1 \| sed 's;https://;;g')  
- docker build -t $IMAGE:$TAG .  
- docker push $IMAGE:$TAG  
- step:  
name: Deploy to ECS  
script:  
- pipe: atlassian/aws-ecs-deploy:1.8.0  
variables:  
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY  
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY  
AWS_DEFAULT_REGION: $AWS_REGION  
CLUSTER_NAME: 'myapp-cluster'  
SERVICE_NAME: 'testapp-service'  
TASK_DEFINITION: 'task-definition.json'  
FORCE_NEW_DEPLOYMENT: 'true'


Answers:
author: Igor Stoyanov
body: [@Venkat P](/t5/user/viewprofilepage/user-id/5311726) Thanks for your question. Please, take a look at [this answer](https://community.atlassian.com/t5/Bitbucket-questions/I-have-a-code-for-pushing-AWS-ECR-image-and-then-updating-the/qaq-p/2079656#M83807).  

Regards, Igor

comments: author: Venkat P
body: Thanks for you answer Igor,

still I'm getting below error, I have mentioned my yml file below can you please suggest anything need to add?

**Error: Docker push error: EOF**

image: python:3.7.4-alpine3.10  
pipelines:  
tags:  
ecr-release-\*:  
- step:  
name: build \& push the docker image  
services:  
- docker  
caches:  
- pip  
oidc: true  
script:  
# build the image  
- pip3 install awscli  
- IMAGE="709724358365.dkr.ecr.ap-south-1.amazonaws.com/testrepo"  
- TAG=latest  
- aws configure set aws_access_key_id $AWS_ACCESS_KEY  
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY  
- aws configure set AWS_DEFAULT_REGION $AWS_REGION  
- eval $(aws ecr get-login --no-include-email --region ap-south-1 \| sed 's;https://;;g')  
- docker build -t my-docker-image .

# use the pipe to push the image to AWS ECR  
- pipe: atlassian/aws-ecr-push-image:1.5.0  
variables:  
AWS_DEFAULT_REGION: $AWS_REGION  
IMAGE: $IMAGE  
TAG: $TAG  
AWS_OIDC_ROLE_ARN: 'arn:aws:iam::709724358365:role/ecsdeployrole'  
IMAGE_NAME: my-docker-image  
- step:  
oidc: true  
script:  

- pipe: atlassian/aws-ecs-deploy:1.6.2  
variables:  
AWS_DEFAULT_REGION: $AWS_REGION  
AWS_OIDC_ROLE_ARN: 'arn:aws:iam::709724358365:role/ecsdeployrole'  
CLUSTER_NAME: 'myappcluster'  
SERVICE_NAME: 'testapp-service'  
TASK_DEFINITION: 'task-definition.json'


author: Igor Stoyanov
body: [@Venkat P](/t5/user/viewprofilepage/user-id/5311726) . I think this is not necessary:  
"""  
- pip3 install awscli  
- IMAGE="709724358365.dkr.ecr.ap-south-1.amazonaws.com/testrepo"  
- TAG=latest  
- aws configure set aws_access_key_id $AWS_ACCESS_KEY  
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY  
- aws configure set AWS_DEFAULT_REGION $AWS_REGION  
- eval $(aws ecr get-login --no-include-email --region ap-south-1 \| sed 's;https://;;g')  
"""

<br />

Just:

"""

- docker build -t my-docker-image .

# use the pipe to push the image to AWS ECR  
- pipe: atlassian/aws-ecr-push-image:1.5.0  
... and so on  
"""

<br />

According to your error:   
[Error: Docker push error: EOF](https://stackoverflow.com/questions/45342682/how-to-fix-eof-error-during-docker-push-command) , seems like you don't have ECR repository, check prerequisites in [aws-ecr-push-image pipe](https://bitbucket.org/atlassian/aws-ecr-push-image/src/master/)  

Regards, Igor  

<br />


author: Igor Stoyanov
body: [@Venkat P](/t5/user/viewprofilepage/user-id/5311726) some info. If you had setup AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY, AWS_REGION as **Repository variables,** the pipe will automatically use them according to: h[ttps://bitbucket.org/atlassian/aws-ecr-push-image/src/12710693b00ae7438763a360359d5b41b3de0135/pipe.yml#lines-6](https://bitbucket.org/atlassian/aws-ecr-push-image/src/12710693b00ae7438763a360359d5b41b3de0135/pipe.yml#lines-6)

Regards, Igor


Tags: aws

bitbucket-cloud

cloud