Php – From Bitbucket to Elastic beanstalk – PHP deployment

amazon-web-serviceselastic-beanstalkPHP

Context

A PHP project is set up on bitbucket cloud. The code is developed locally in XAMPP. The code runs in Amazon Web Service Elastic Beanstalk environment.

Problem

I commit my changes locally and then push to Bitbucket. Now I need to deploy from Bitbucket to the AWS Elastic Beanstalk instance.

I don't want any other tools to be used in-between to do this nor use the zip file to upload to Elastic Beanstalk. Instead perform directly from Bitbucket to Elastic Beanstalk. How can I do this?

Best Answer

I've had a similar issue, needing to deploy to Elastic Beanstalk from Bitbucket. While mine is a Python application, the following is language-agnostic.

  • Use Bitbucket pipelines to zip up your code and drop it into a versioned S3 bucket (versioning is important here)
  • Create a pipeline in AWS CodePipeline to pick up the zip file from the S3 bucket Bitbucket has just dropped the bundle into. AWS CP will use the versioning notification topic that's silently published within AWS's systems to automatically trigger.
  • Set the pipeline's deployment phase to be your Elastic Beanstalk environment.

I've been using this method for a while now and not really had a problem with it. We have other sections that belong to both Bitbucket's and AWS's Pipeline (testing and building docker images), but this method should work just fine without the "build" phase in CodePipeline.