Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot Deploy my artifact to Amazon EC2 via CodeDeploy

Hitendra Verma July 11, 2019

Hello, 

 

I am trying to setup a bitbucket pipeline to deploy a simlple zip artifact to an EC2 instance via Codedeploy. I am using the following article published by Atlassian: https://confluence.atlassian.com/bitbucket/deploy-to-amazon-aws-875304040.html

 

The pipeline succeeds till uploading to S3 and then fails when doing the deploy with this error:

 

Status: Downloaded newer image for bitbucketpipelines/aws-code-deploy:0.2.3
INFO: Deploying app from revision.aws deploy get-application-revision --application-name SampleCodeDeployPega --revision revisionType=S3,s3Location={bucket=SampleCodeDeployPega-codedeploy-deployment,bundleType=zip,key=SampleCodeDeployPega-13-e912d59c}
An error occurred (RevisionDoesNotExistException) when calling the GetApplicationRevision operation: No application revision found for revision.
✖ Failed to fetch revision.

 

I have all the proper IAM roles assigned to the user (AmazonS3FullAccess and AWSCodeDeployFullAccess) and I am using the correct access key and credentials. 

 

I followed the steps in the article and below are the files:

 

bitbucket-pipeline.yml

image: atlassian/default-image:2

pipelines:
default:
- step:
name: Build
script:
- echo "Deploying to test environment"
artifacts:
- myapp.zip

- step:
name: Upload to S3
script:
# Test upload
- pipe: atlassian/aws-code-deploy:0.2.6
variables:
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}
COMMAND: 'upload'
APPLICATION_NAME: ${APPLICATION_NAME}
S3_BUCKET: ${S3_BUCKET}
ZIP_FILE: 'myapp.zip'

- step:
name: Deploy with CodeDeploy
script:
# Test upload
- pipe: atlassian/aws-code-deploy:0.2.6
variables:
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}
COMMAND: 'deploy'
APPLICATION_NAME: ${APPLICATION_NAME}
DEPLOYMENT_GROUP: ${DEPLOYMENT_GROUP}
VERSION_LABEL: 'my-app-1.0.0'
IGNORE_APPLICATION_STOP_FAILURES: 'true'
FILE_EXISTS_BEHAVIOR: 'OVERWRITE'
WAIT: 'true'

 

appspec.yml:

version: 0.0
os: linux
files:
- source: myapp.zip
destination: /opt/pega/staging
hooks:
BeforeInstall:
- location: scripts/import.sh
timeout: 300
runas: pguser 

This is my directory structure in bitbucket repository:

image.pngAll help, hints, suggestions welcome. Thank you for helping out. 

1 answer

1 accepted

0 votes
Answer accepted
Hitendra Verma July 15, 2019

If anyone is looking for an answer to a similar question, here you go:

I needed to specify the "S3_BUCKET: ${S3_BUCKET}" variable in both the upload and deploy steps. 

Once I did that, the deployment suceeded. 

rao999 July 18, 2019

Hi Hitendra verma,

I am also facing the same issue , but i mentioned s3 bucket variable even the deployment has failed.

image: node:10.15.0

pipelines:
default:
- step:
name: Build
script:
- apt-get update -y
- cd admin/front-end/
- npm install
- CI=false
- npm run build
- apt-get install -y zip
- zip -r myapp.zip *
artifacts:
- admin/front-end/myapp.zip

- step:
name: Upload to S3
script:
- pipe: atlassian/aws-code-deploy:0.2.3
variables:
AWS_DEFAULT_REGION: 'us-east-1'
AWS_ACCESS_KEY_ID: 'AKIAXWJT4X2UTL2URGQJ'
AWS_SECRET_ACCESS_KEY: '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'
COMMAND: 'upload'
APPLICATION_NAME: 'codedeployapplication'
ZIP_FILE: 'admin/front-end/myapp.zip'
S3_BUCKET: 'codedeployrole'
VERSION_LABEL: 'my-app-1.0.0'

- step:
name: Deploy with CodeDeploy
services:
- docker
script:
- pipe: atlassian/aws-code-deploy:0.2.6
variables:
AWS_DEFAULT_REGION: 'us-east-1'
AWS_ACCESS_KEY_ID: 'AKIAXWJT4X2UTL2URGQJ'
AWS_SECRET_ACCESS_KEY: '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'
COMMAND: 'deploy'
APPLICATION_NAME: 'codedeployapplication'
DEPLOYMENT_GROUP: 'DG1'
VERSION_LABEL: 'my-app-1.0.0'
IGNORE_APPLICATION_STOP_FAILURES: 'true'
FILE_EXISTS_BEHAVIOR: 'OVERWRITE'
S3_BUCKET: 'codedeployrole'
WAIT: 'true'

Hitendra Verma July 18, 2019

Hi,

First, please don't share your access_key and access_key_id in public. It is not secure and leaves your account vulnerable.

second, you are using two different versions of the code-deploy pipeline in your code: 0.2.3 and 0.2.6. Please make the version consistent in your build yaml and run the pipeline again.

If it fails again, please post the full log from the "upload" and "deploy" steps. 

tech71 July 18, 2019

Hi Hitendra,
Thanks for your reply As per your suggestions I have maintained the same version of pipe even also i am facing the same error Please check I  have attached my logs as per your requirement.
Bitbucket codes:-
image: node:10.15.0

pipelines:
  default:
    - step:
        name: Build
        script:
          - apt-get update -y
          - cd admin/front-end/
          - npm install
          - CI=false
          - npm run build
          - apt-get install -y zip
          - zip -r myapp.zip *
        artifacts:
          - admin/front-end/myapp.zip

    - step:
        name: Upload to S3
        script:
          - pipe: atlassian/aws-code-deploy:0.2.3
            variables:
              AWS_DEFAULT_REGION: 'us-east-1'
              AWS_ACCESS_KEY_ID: '=============='
              AWS_SECRET_ACCESS_KEY: '==============I'
              COMMAND: 'upload'
              APPLICATION_NAME: 'codedeployapplication'
              ZIP_FILE: 'admin/front-end/myapp.zip'
              S3_BUCKET: 'codedeploys3bucket09'
              VERSION_LABEL: 'my-app-1.0.0'

    - step:
        name: Deploy with CodeDeploy
        services:
          - docker
        script:
          - pipe: atlassian/aws-code-deploy:0.2.3
            variables:
              AWS_DEFAULT_REGION: 'us-east-1'
              AWS_ACCESS_KEY_ID: '=============='
              AWS_SECRET_ACCESS_KEY: '====================='
              COMMAND: 'deploy'
              APPLICATION_NAME: 'codedeployapplication'
              DEPLOYMENT_GROUP: 'DG2'
              WAIT: 'true'
              S3_BUCKET: 'codedeploys3bucket09'
              VERSION_LABEL: 'my-app-1.0.0'
              IGNORE_APPLICATION_STOP_FAILURES: 'true'
              FILE_EXISTS_BEHAVIOR: 'OVERWRITE'

Please find the atatched logs :-Capture0.PNGCapture01.PNGCapture02.PNG

Hitendra Verma July 19, 2019

hi, 

from your screenshots, all steps look correct and the application revision and s3 bucket name all match.

at this point you need to check your application setup in codedeploy and make sure that codedeploy is able to deploy to the EC2 instance that you have selected as a target. Try checking the IAM role, instance tag, and permissions to allow codedeploy to access the EC2 instances you need. 

rao999 July 19, 2019

Hi Hitendra, 

Yes I have checked the I AM role and I have allowed them s3 full permission and code deploy role full permission to that role attached to EC2 and code deploy agent installed. 

and I communicated with AWS team they are telling ur appspec. Yml file is not zipped to the s3. 

When appspec. Yml file uploads to s3 while zipping maybe it will get successful. 

 

Here I how modify my codes to zip the appspec. Yml file can you please help? 

 

Regards, 

Venkat

9052325074

Hitendra Verma July 29, 2019

Hi, 

So what I am doing is that my zip file contains the appspec.yml already. I have a step in the build section which zips up all the files in the app folder including the appspec.yml file. 

 

Here is what the steps look like in bitbucket yml file:

  - step: 
name: Build
script:
- cd app && zip -r ../myapp.zip *
artifacts:
- myapp.zip

 

In the "app" folder I have my application code. some scripts and the appspec.yml file.

 

Try it, that should work. 

Ibrahim
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 2, 2020

did anyone resolve this issue, cause recently I am facing this issue, it was all good for more than a year and since yesterday I am facing this issue?

Like ankit likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events