You can reduce the script lines by the fact that you can also deploy straight from S3 or public URL without needing to call aws amplify create-deployment as follows:
It should also be a little less error sensitive when you can use zip files already uploaded to S3 and don't have to upload them again with curl.
Here is full modified example:
#!/bin/basharchive="archive.zip"s3_bucket="elasticbeanstalk-eu-west-3-something"amplify_id="something"git_branch=$(git rev-parse --abbrev-ref HEAD)if[-f"$archive"];then
printf"Delete previously created archive\n"rm"$archive"fi# We create the Nuxtjs dist/ build directory printf"Make bundle build\n"
yarn run build
# Create the archive of the dist/ directoryprintf"Create the code archive\n"
zip -q-r$archive dist/*# Check that the latest archive on s3 is not the same as the one we just created# to avoid useless deploymentsprintf"Generate current deploy checksum\n"CURRENT_MD5=$(find dist/ -type f -execmd5sum{}\; | sort-k 2 | md5sum)printf"Verify latest deploy checksum\n"LATEST_MD5=$(aws s3api head-object --bucket$s3_bucket--key$archive\
| jq -r'.Metadata.md5')if["$CURRENT_MD5"="$LATEST_MD5"];then# No deploy requiredprintf"The Latest project version is already deployed\n"else# Save the archive to S3 with the MD5 checksum in metadata to simplify # checks in the next deployment
aws s3 cp$archive s3://$s3_bucket/ --metadatamd5="$CURRENT_MD5"# Start the deploymentprintf"Start Amplify deployment\n"
aws amplify start-deployment \--app-id$amplify_id\--branch-name$git_branch\--source-url s3://$s3_bucket/$archive> amplify-deploy-job.json
AMPLIFY_JOB_ID=$(cat amplify-deploy-job.json \
| jq -r'.jobSummary.jobId')while :
do
sleep 10
# Poll the deployment job status every 10 seconds until it's not pending# anymoreSTATUS=$(aws amplify get-job \--app-id$amplify_id\--branch-name$git_branch\--job-id$AMPLIFY_JOB_ID\
| jq -r'.job.summary.status')if[$STATUS!='PENDING'];then
break
fi
done
printf"Amplify deployment status $STATUS\n"fi
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You can reduce the script lines by the fact that you can also deploy straight from S3 or public URL without needing to call
aws amplify create-deployment
as follows:It should also be a little less error sensitive when you can use zip files already uploaded to S3 and don't have to upload them again with curl.
Here is full modified example: