How do I deploy a Python application to Amazon Elastic Beanstalk from Jenkins? How do I deploy a Python application to Amazon Elastic Beanstalk from Jenkins? jenkins jenkins

How do I deploy a Python application to Amazon Elastic Beanstalk from Jenkins?


To correct the config profile (eb-cli) could not be found error, drop the credentials you are using to deploy to EB into ~/.aws/config for your jenkins user on your jenkins machine. If you built your deployment on a local machine, you should be able to pull the file directly from ~/.aws/config locally. It will look like this:

[profile eb-cli]aws_access_key_id = (for your IAM user)aws_secret_access_key = (for your IAM user)


I resolved this by sshing into the Jenkins machine, running eb init, and then comparing the generated .elasticbeanstalk/config.yml with the one in the here-doc I was using above. The two were different because of the different security profiles on my development machine versus the Jenkins machine.

We can rewrite this script to be more robust against different config.yaml files like this:

virtualenv env && source env/bin/activate && pip install awsebcliecho "1" | eb init myapp --region us-west-2 && eb use myenv && eb deploy myenv

Note, we use echo "1" | eb init myapp --region us-west-2 to select a default environment since eb init does not take environment as a positional argument and then use eb use myenv to select the environment we want.


We ran into this issue out of the blue, this may or may not be relevant, but I wanted to get this out there for anyone that might run across this again. The eb-cli seems to have changed slightly and will not allow credentials to be set globally.

Our JenkinsFile looks like this

 withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',  credentialsId: 'iam-creds']]) {       sh "pip install awsebcli --upgrade --user"       sh "~/.local/bin/eb use my-application"       sh "~/.local/bin/eb deploy --verbose"     }

and our config.yml looks like this

 global:   application_name: my-application   default_ec2_keyname: application-keyname   ...   profile: eb-cli   sc: git   workspace_type: Application

removing the profile key solves the issue... However, this disallows deployments from the local machine (unless there is a way to use globals)