I have setup an AWS Pipeline that automatically sources my code from an S3 Bucket, Builds it and Deploys it to EC2 instances. I would now like to run some shell commands (eg: Start a python script) automatically. How can I integrate that in Pipeline?
1 Answer
If you're using code deploy, the answer is in your appspec.yml file which provides for the execution of commands at certain lifecycle hooks in the deployment.
I'm guessing you want the "ApplicationStart" hook. you use hooks by adding a section like:
hooks:
BeforeInstall:
- location: Scripts/UnzipResourceBundle.sh
- location: Scripts/UnzipDataBundle.sh
AfterInstall:
- location: Scripts/RunResourceTests.sh
timeout: 180
ApplicationStart:
- location: Scripts/RunFunctionalTests.sh
timeout: 3600
ValidateService:
- location: Scripts/MonitorService.sh
timeout: 3600
runas: codedeployuser
Code example from AWS docs: https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-example.html
pretty much the deployer agent will run the commands in the "location" clause at the given life cycle hook. As you can see, there are other options which are fullly documented in code deploy docs.
If you're using CodePipeline with some alternate deployment agent, best bet is to ask a question about that deploy agent or look at their docs. Pipeline just coordinates a code repo, a build agent and a deploy agent. It doesn't actually do the deployment itself or execute deployment commands.