Search code examples
aws-code-deploy

Writing an appspec.yml File for Deployment from S3 (and/or Bit Bucket) to AWS CodeDeploy


I'd like to make it so that a commit to our BitBucket repo (or S3 Bucket) automatically deploys code (using CodeDeploy) to our EC2 instances. I'm not clear what to use for the 'source' and 'destination' entry under the 'files' section in the appspec.yml file and also I am not cleared what to mention in BeforeInstall and AfterInstall under 'Hooks' section. I've found some examples on Google and AWs documentation but I am confused what to mention in above fields. The more I am exploring more I am getting confused. Consider I am new to AWS Code Deploy. Also it will be very helpful if someone can provide me step y step link how to configure and how to automate the CodeDeploy. I was wondering if someone could help me out?

Thanks in advance for your help!


Solution

  • Thanks for using CodeDeploy. For new users, I'd like to recommend the following things to do:

    • Try to run First Run Wizard on console, it will should you the general process how the deployment goes. It also provide a default deployment bundle, also an appspec file included.

    • Once you want to try a deployment yourself, the Get Started doc is a great place to help you with some pre-requiste settings like IAM role

    • Then probably try some tutorials for a sample app too, which gives you some idea about deployment groups, deployment configuration, revision and so on.

    • The next step should be create a bundle for your own use cases, Appspec file doc would be a great place to refer. And for your concerns about BeforeInstall and AfterInstall, if your application doesn't need to do anything, the lifecycle events can be left as empty. BeforeInstall can be used to for for preinstall tasks, such as decrypting files and creating a backup of the current version, while AfterInstall can be used for tasks such as configuring your application or changing file permissions.

    • Now it comes to the fun part! This blog talks about details about how to integrate with Github(similar for Bitbucket). It's a little long, but really useful, and it also includes how to do automatically deployment once there is a new pushed commit. Currently Jenkins and CodePipline are really popular for auto-triggered deplyoments, but there are always a lot of other ways can achieve the same purpose like Lamda and so on