I want to use AWS CodeDeploy to deploy a jar file and then run my java -jar
command from there once it is on the EC2. But I've noticed that AWS CodeDeploy only pulls zip
, tar
and tar.gz` from S3. I'm thinking I will use CLI from my local jenkins to push a .zip file (containing the jar) to S3, then run another CLI command to start AWS CodeDeploy which will pull the .zip from S3.
However I do have a question the details on AWS CodeDeploy:
Can I use the appspec.yml to issue two commands,
1) unzip the .zip from S3 once it is on the EC2
2) Issue the java -jar
on a specific location?
Thanks
1) You do not need issue an unzip command, the files section in appspec.yml is used to specify the files in your archive (source) you wish to copy to the file system on ec2 (destination) and will be done by the code deploy agent RE https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-files.html
2) Create a run script to issue java -jar command under the hook ApplicaitonStart RE https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html
Example appspec.yml on os linux based:
version: 0.0
os: linux
files:
- source: ./
destination: /home/ubuntu/myapp
hooks:
ApplicationStart:
- location: runapp.sh
runas: ubuntu
runapp.sh:
#!/usr/bin/env bash
echo 'Starting my app'
cd '/home/ubuntu/myapp'
java -jar myapp.jar
In this example, you would include runapp.sh in your deployment package