Amazon S3 publishing using codemagic.yaml
How to publish build artifacts to Amazon S3 using codemagic.yaml
In order to publish your web application to AWS S3, you need to configure your access credentials in Codemagic. You can follow the instructions provided by Amazon to create your account and get the necessary details.
Open your Codemagic app settings, and go to the Environment variables tab.
Enter the desired Variable name, e.g.
AWS_ACCESS_KEY_ID
.Enter the required value as Variable value.
Enter the variable group name, e.g. aws_credentials. Click the button to create the group.
Make sure the Secure option is selected.
Click the Add button to add the variable.
Repeat the process to also add the
AWS_SECRET_ACCESS_KEY
variable.Add the script below to your
scripts
section before your build script to update the S3 bucket.<FOLDER OR FILE>
refers to a specific folder or file to be synced. Replace<BUCKET_NAME>
with your actual bucket name. Note that all the artifact files that Codemagic generates during the build are located inCM_BUILD_OUTPUT_DIR
.
environment:
groups:
- aws_credentials
scripts:
- name: Update S3 bucket
script: |
aws s3 sync <FOLDER OR FILE> s3://<BUCKET_NAME>
Now, each time you build the workflow, the app artifact will be published to your Amazon S3 bucket.
Note that the minimal required permission policy attached to the AWS IAM is as follows:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::<bucket-name>/*"
}
]
}