Deploying to S3 using atlassian/aws-s3-deploy pipe fails with status 2 error.
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
When using the pipe atlassian/aws-s3-deploy to deploy artifacts (generated in a previous build step) from your build to an AWS S3 instance, the pipe fails with an aws cli status 2 error.
Environment
Bitbucket Pipelines on Bitbucket Cloud
Diagnosis
The pipelines logs for the execution of atlassian/aws-s3-deploy returns an error similar to the following:
1
2
3
4
5
6
7
status=2
+ set -e
+ [[ 2 -eq 0 ]]
+ fail 'Deployment failed.'
+ echo -e '\e[31m✖ Deployment failed.\e[0m'
+ exit 1
✖ Deployment failed.
Cause
As per AWS documentation, the status 2 code for the aws cli s3 command, which is used by the pipe, means that aws cli do not have sufficient permissions to access the file(s)/folder(s) configured to be sent to the S3 instance.
In Bitbucket pipelines, when using artifacts to share files from one step to subsequent steps, the artifacts are uncompressed by the pipelines agent in the Build Setup phase, and these files/folders from the artifact are owned by the pipelines user with default permissions as 644 (-rw-r–r–). Since the pipe atlassian/aws-s3-deploy runs with root user - not pipelines user - the commands executed by the pipe might not have sufficient permission to access the files originating from an artifact, leading to the failure in pipe execution with status 2 error.
Solution
Since the error is related to file permissions, you can grant full access to the folder(s)/files(s) being deployed by running a chmod 777 before the pipe command, so this will grant that atlassian/aws-s3-deploy will have all the access it requires when sending these file(s)/folder(s) to the S3 instance:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pipelines:
default:
- step:
name: Build code and generate artifact
script:
- my_build_script.sh
artifacts:
- build/web # generates an artifact from build/web/ folder that will be available in the next steps.
- step:
name: Uploading to AWS
script:
- chmod -R 777 build/web/ #updates the permissions recursevely (-R) for all the files in build/web/ folder.
- pipe: atlassian/aws-s3-deploy:1.1.0. #pipe that will deploy the folder build/web/
variables:
AWS_DEFAULT_REGION: $AWS_REGION
S3_BUCKET: $MY_S3BUCKET
LOCAL_PATH: 'build/web'
DEBUG: 'true'. # Enables verbose logs for troubleshooting if needed
Was this helpful?