• Can u please suggest me how effective is AWS codeDeploy for Magento 2 ?
  • Is there any problems i need to overcome?

Sharing your experience would be helpful for me. Thankyou.


This is a very "BIG" topic but I will cover the basics here

ASSUMING YOU ALREADY HAVE an AWS account and CodeDeploy setup

Here are the basic that we take on a deployment for M2

Here is the appspec.yml file

version: 0.0
os: linux
        - location: config_files/scripts/beforeInstall.bash
          runas: root
        - location: config_files/scripts/afterInstall.bash
          runas: mage_user
        - location: config_files/scripts/moveToProduction.bash
          runas: root
        - location: config_files/scripts/cacheclean.bash
          runas: mage_user

Script to compile - You pull and compile code to a deploy server

cd production/build/public_html
git checkout .
git pull origin master
rm -rf var/cache/* var/page_cache/* var/composer_home/* var/tmp/*
php composer.phar update --no-interaction --no-progress --optimize-autoloader
bin/magento setup:upgrade

bin/magento setup:static-content:deploy -t Magento/backend
bin/magento setup:static-content:deploy en_US es_ES -a frontend

bin/magento setup:di:compile

# Make code files and directories read-only
echo "Setting directory base permissions to 0750"
find . -type d -exec chmod 0750 {} \;
echo "Setting file base permissions to 0640"
find . -type f -exec chmod 0640 {} \;
chmod o-rwx app/etc/env.php && chmod u+x bin/magento

# Compress source at shared directory
if [ ! -d /build ]; then
    mkdir -p /build
tar -czvf /build/build.tar.gz . --exclude='./pub/media' --exclude='./.htaccess' --exclude='./.git' --exclude='./var/cache' --exclude='./var/composer_home' --exclude='./var/log' --exclude='./var/page_cache' --exclude='./var/import' --exclude='./var/export' --exclude='./var/report' --exclude='./var/backups' --exclude='./var/tmp' --exclude='./var/resource_config.json' --exclude='./var/.sample-data-state.flag' --exclude='./app/etc/config.php' --exclude='./app/etc/env.php'

Now you can deploy to your pre-configured group

sh ./compile.sh
aws deploy create-deployment \
--application-name AppMagento2 \
--deployment-config-name CodeDeployDefault.OneAtATime \
--deployment-group-name MyMagentoApp \
--description "Live Deployment" \
--s3-location bucket=mage-codedeploy,bundleType=zip,eTag=<tagname>,key=live-build2.zip

I created this script to show where you are in the deployment


aws deploy get-deployment --deployment-id $1 --query "deploymentInfo.[status, creator]" --output text
  • Thank you for your valuable information. I tried CodePipeline with aws codedeploy via BlueGreen deployment for the magento 2 setup with my custom bash scripts, everything worked fine but am still not clear how can i test my replacement environment . To test the replacement environment, it should able to access the same database which original environment uses. Am not sure how can i make my replacement environment to access the same database and also how good i can create the AMI with nginx configuration for the ASG to create the replacement environment while deployment? – Prabhu M. May 16 '18 at 6:29
  • Can we overcome this by multiple website or multiple store concept in magento 2? how? – Prabhu M. May 16 '18 at 6:30
  • First can you please mark that answer as accepted? – brentwpeterson May 17 '18 at 13:32
  • Its accepted now. Sorry, am new to stackExchange. Now can you answer my above query? – Prabhu M. May 19 '18 at 14:03
  • You said it "worked fine" so I don't understand? Did you not deploy to your new environment? What didn't work fine? – brentwpeterson May 19 '18 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.