3

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
  • are you using codedeploy ro some other deployment service? Commented Nov 2, 2018 at 21:13

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

That makes sense but still not working, in case I'll followup with another question
you need to put your shell command file in the listed location (location is relative to the deployment location unless you make it absolute) and also make sure the deployer has the appropriate permissions or use sudo appropriately.
Yes that's fine, basically what I'm trying to do is to copy one of the directories deployed into a docker container by using docker cp but.... it appears the directory isn't actually there when AfterInstall is called
integrating this with docker is not something I've ever really tried so there could definitely be some gotchas there. There usually is
Ok so as you were saying I was using the wrong directory, I now put the absolute path and we shall see...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.