having issue deploying .NET API to ec2 using CodeDeploy pipe with bitbucket pipeline
Asked by HB:

So i'm having this error when trying to deploy to ec2 instance from S3 with bitbucket pipeline :  
![commuask.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/202805i0F1D44F0A4897D35/image-size/large?v=v2&px=999 "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'



```


Answers:
author: Patrik S
body: Hello [@EunoiaCode](/t5/user/viewprofilepage/user-id/4968888) ,

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 :

* <https://bitbucket.org/product/features/pipelines/integrations?p=atlassian/aws-code-deploy>

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

Thank you, [@EunoiaCode](/t5/user/viewprofilepage/user-id/4968888) .

Kind regards,

Patrik S


Tags: bitbucket-cloud

cloud