Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Bitbucket Pipelines Failed to fetch revision while trying to build a Blue/Green flow

Jose Pablo Sanchez July 3, 2022

I'm trying to configure a simple CI/CD flow using AWS and Bitbucket Pipelines, everything is working as should, but when the deployment to CodeDeploy comes in, it stops with an error message.

This is the diagram of my setup:

Build and push Docker Image to ECR(Ok) -> Deploy to ECS(Ok) -> Upload to AWS CodeDeploy(Ok) -> Deploy to AWS CodeDeploy(Fails)

As you can see, it's a pretty straightforward setup, so I think that this simplicity makes it a bit harder to understand where the problem can be.

Complete error message:

✖ Failed to fetch revision..
An error occurred (RevisionDoesNotExistException) when calling the GetApplicationRevision operation: No application revision was found for revision.

Error message with DEBUG enabled:

DEBUG: Response body:
b'{"__type":"RevisionDoesNotExistException","message":"No application revision found for revision."}'
DEBUG: Response headers: {'x-amzn-RequestId': '2bcb3131-aa53-4ce1-a84b-4c86059e9d12', 'Date': 'Sun, 03 Jul 2022 22:01:46 GMT', 'Content-Type': 'application/x-amz-json-1.1', 'Content-Length': '98'}
DEBUG: Response body:
b'{"__type":"RevisionDoesNotExistException","message":"No application revision found for revision."}'
DEBUG: Event needs-retry.codedeploy.GetApplicationRevision: calling handler <botocore.retryhandler.RetryHandler object at 0x7f2cfeef5040>
DEBUG: No retry needed.

The thing I've already tried:

- Review user permissions and services roles.
- Review all my variables, mostly to verify if everything was in the same region and things like that.
- Review S3 routes to verify that the files exist and where in the place that they should.
- Manually replicate the setup step by step using only the AWS Console. (With success)
- Use DEBUG inside the Upload script, It doesn't show anything helpful.

These are the Upload & Deploy section of my pipeline.yml

**Upload**

upload-to-codedeploy: &upload-to-codedeploy
name: Upload to AWS CodeDeploy
image: php:8.0-apache
script: # Test
- pipe: atlassian/aws-code-deploy:1.1.1
variables:
# Common Variables
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID # Optional if already defined in the context.
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY # Optional if already defined in the context.
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION # Optional if already defined in the context.
APPLICATION_NAME: 'dev-test-deploy'
COMMAND: 'upload' # 'upload' or 'deploy'.
S3_BUCKET: $S3_BUCKET
# Upload Variables
ZIP_FILE: 'appspec.zip'
BUNDLE_TYPE: 'zip'
FOLDER: 'pipeline'
VERSION_LABEL: $S3_BUCKET
DEBUG: 'true'

**Deploy**

deploy-to-codedeploy: &deploy-to-codedeploy
name: Deploy to AWS CodeDeploy
image: php:8.0-apache
script: # Test
- pipe: atlassian/aws-code-deploy:1.1.1
variables:
# Common Variables
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID # Optional if already defined in the context.
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY # Optional if already defined in the context.
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION # Optional if already defined in the context.
APPLICATION_NAME: 'dev-test-deploy'
S3_BUCKET: $S3_BUCKET
BUNDLE_TYPE: 'YAML'
WAIT: 'true'
# Upload Variables
ZIP_FILE: 'appspec.yaml'
# Deploy specific variables
DEPLOYMENT_GROUP: "dev-test-deploy-group"
#VERSION_LABEL: 'app-$(date +%Y-%m-%d)-1'
COMMAND: 'deploy' # 'upload' or 'deploy'.
IGNORE_APPLICATION_STOP_FAILURES: 'true'
FILE_EXISTS_BEHAVIOR: 'OVERWRITE'
FOLDER: 'pipeline'
VERSION_LABEL: $S3_BUCKET
DEBUG: 'true'

**appspec.yaml**

version: 0.0
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: "arn:aws:ecs:us-east-1:891903962143:task-definition/cb-app-task"
LoadBalancerInfo:
ContainerName: "php-docker"
ContainerPort: 80

 

Any help would be welcome, thanks.

1 answer

1 accepted

0 votes
Answer accepted
Jose Pablo Sanchez July 4, 2022

Ok, so I figured out what was wrong, these are the steps that I followed:

 

1- Like the error says "No application revision found", Codedeploy wasn't capable of finding the .yml file that the process of Upload did, so after reviewing my congifs and making sure that everything was in the correct place(S3), so I did the registration by hand:

 

aws deploy register-application-revision \
--application-name myapp \
--description "Revised my app application" \
--s3-location bucket=mybucket-s3,key=appspec.zip,bundleType=zip

 Here are two things that are very important, the appspec.zip file and the content of it.

For the content I only used the appspec.yml file, and thats it, thats everything that the .zip need.

appspec.yml

 version: 0.0

 Resources:

   - TargetService:
        Type: AWS::ECS::Service
        Properties:
          TaskDefinition: "arn:aws:ecs:us-east-1:12345678:task-definition/my-app-task"
          LoadBalancerInfo:
            ContainerName: "docker-image-name"
            ContainerPort: 80
2- After reviewing my Upload and Deploy steps, here is the final code of each one

Upload

upload-to-codedeploy: &upload-to-codedeploy
name: Upload to AWS CodeDeploy
image: php:8.0-apache
script: # Test
    - pipe: atlassian/aws-code-deploy:1.1.1
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY 
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
  APPLICATION_NAME: 'dev-test-deploy'
COMMAND: 'upload' # 'upload' or 'deploy'.
S3_BUCKET: $S3_BUCKET
ZIP_FILE: 'appspec.yml'
BUNDLE_TYPE: 'YAML' # Lambda and ECS
VERSION_LABEL: 'appspec.yml'

Deploy

      deploy-to-codedeploy: &deploy-to-codedeploy
          name: Deploy to AWS CodeDeploy
          image: php:8.0-apache
          script: # Test
          - pipe: atlassian/aws-code-deploy:1.1.1
            variables:
              AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
              AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
              AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
              APPLICATION_NAME: 'dev-test-deploy'
              S3_BUCKET: $S3_BUCKET
              BUNDLE_TYPE: 'YAML'
              WAIT: 'true'
              ZIP_FILE: 'appspec.yml'
              DEPLOYMENT_GROUP: 'dev-test-deploy-group' 
              FILE_EXISTS_BEHAVIOR: 'OVERWRITE'
              VERSION_LABEL: 'appspec.yml'
              DEBUG: 'true'      

 

I hope I have been clear, if I can help with something else please create a comment here.

One important note here, please, always read the docs, they are crucial.

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events