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

having issue deploying .NET API to ec2 using CodeDeploy pipe with bitbucket pipeline

HB June 21, 2022

So i'm having this error when trying to deploy to ec2 instance  from S3 with bitbucket pipeline :

commuask.PNG

and  how pipeline looks like:

- step:
name: 'Deployment to S3 Bucket'
deployment: S3Bucket
trigger: 'automatic'
script:
- echo "Your deployment to S3 Bucket script goes here..."
- pipe: atlassian/aws-s3-deploy:1.1.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
S3_BUCKET: 'webserver-for-weaplan-2/weaplanservicesV1'
LOCAL_PATH: '$(pwd)'

##---------------DEPLOYMENT-OF-DATAHANDLERAPI-TO-WEAPLAN-EC2-INSTANCE-------------##
- step:
name: Deploy DataHandlerAPI to EC2 instance
deployment: DH_EC2
trigger: 'automatic'
script:
- 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: 'DataHandlerAPI'
COMMAND: 'deploy'

S3_BUCKET: 'webserver-for-weaplan-2/weaplanservicesV1'

DEPLOYMENT_GROUP: 'DataHandlerAPI-dg'



1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 23, 2022

Hello @EunoiaCode ,

Welcome to Atlassian Community!

The error being shown suggests the application name you are trying to deploy in the aws-code-deploy pipe does not match with any application name registered in your S3 bucket.

Also, I see you are uploading an entire directory to your S3 bucket, but the aws-code-deploy pipe only supports the deployment of files that are bundled in zip, tar, tgz, YAML or JSON. 

That said, I would suggest you try updating your YML file accordingly to the below example:

- step:

  name: "Upload to S3 and deploy

  script:

  - apt-get update && apt-get install zip

  - zip -r myapp.zip $(pwd)

  - pipe: atlassian/aws-code-deploy:1.1.1

    variables:

      AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}

      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}

      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}

      COMMAND: 'upload'

      APPLICATION_NAME: 'DataHandlerAPI'

      ZIP_FILE: 'myapp.zip'

      S3_BUCKET: 'webserver-for-weaplan-2/weaplanservicesV1'

      VERSION_LABEL: 'DataHandlerAPI-${BITBUCKET_BUILD_NUMBER}-${BITBUCKET_COMMIT}'

  - pipe: atlassian/aws-code-deploy:1.1.1

    variables:

      AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}

      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}

      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}

      COMMAND: 'deploy'

      APPLICATION_NAME: 'DataHandlerAPI'

      DEPLOYMENT_GROUP: 'DataHandlerAPI-dg'

      WAIT: 'true'

      S3_BUCKET: 'webserver-for-weaplan-2/weaplanservicesV1'

VERSION_LABEL: 'DataHandlerAPI-${BITBUCKET_BUILD_NUMBER}-${BITBUCKET_COMMIT}'

You can notice the pipe atlassian/aws-code-deploy can be used in 2 different modes: upload or deploy, which is controlled by the variable COMMAND, so we are executing the pipe twice to first upload to S3 and then deploy the uploaded zip file.

In the example above, we are first zipping the directory to a file called myapp.zip.

Then, in the first execution of atlassian/aws-code-deploy the zip file will be uploaded to S3 bucket defined in the variable S3_BUCKET, and assigned the label configured in VERSION_LABEL.

In the second execution of atlassian/aws-code-deploy we are deploying the previously uploaded zip file that matches the APPLICATION_NAME and VERSION_LABEL. It's important for the application name and version label to match between what was uploaded to S3 and what is being deployed, otherwise you will likely run into NotFound exceptions, like the one you reported.

You are also welcome to take a look at the atlassian/aws-code-deploy pipe official documentation, which can provide further details on how it works and how it is configured : 

Hope that helps! Let me know if you have any questions.

Thank you, @EunoiaCode .

Kind regards,

Patrik S

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events