I've created an AWS Elastic Beanstalk application and environment. However, I cannot for the life of me figure out how to deploy code to it. Most tutorials I read are for creating a new application directly from the CLI, but I already have one.
I've installed the AWS CLI tools. I created a SSH key-pair to the environment and added it to my .ssh folder. I created an IAM profile and logged in with that in my terminal.
If I understand correctly, I need to do eb use [my environment name] so I can then eb deploy to it. But when I use eb list, nothing comes up. How can I connect to the environment that already exists on AWS?
I am using Linux (WSL on Windows). I'm also on the Free Tier of AWS.
You can either use AWS CLI commands or EB CLI commands to deploy your applications.
Congfigure the source, GIT or S3. e.g. I have uploaded my_app.zip to my_bucket in S3.
Create a new application version. It is a good practise to use commit hash as version label.
aws elasticbeanstalk create-application-version
--application-name <EB_APP_NAME> --version-label <version-label>
--source-bundle S3Bucket="my_bucket",S3Key=my_app.zip --auto-create-application
Update the environment to point to the new application version. The value of version-label should be the same as in the previous step.
aws elasticbeanstalk update-environment
--application-name <EB_APP_NAME>
--environment-name <EB_ENV_NAME>
--version-label <version-label>
The alternative way is to use EB CLI. eb deploy handles all 3 steps above.
Initialize EB CLI using eb init.
Deploy using eb deploy.
Related
I do not want to use the console. No manual processes. I need a command line version, something that I can code in my continuous deployment scripts.
As part of the build process, I can output a ZIP file (be it on my local machine or in CI process, e.g: via bitbucket pipelines or AWS codedeploy VM instance).
I want a command like:
aws eb deploy my-app ./server.zip
That is, first upload my chosen zip file and then deploy it (doesn't have to be one command).
The official eb deploy does not seem to support this, nor have I been able to find any other method to do this.
Any ideas would be much appreciated :)
I don't think eb CLI supports uploading a ZIP and updating an environment but you can use a combination of AWS CLI commands.
Upload the ZIP to S3
Create an application version
Update the environment
Example,
aws s3 cp deploy.zip s3://mybucket/deploy.zip
aws elasticbeanstalk create-application-version --application-name my-app --version-label 12345 --source-bundle S3Bucket="mybucket",S3Key="deploy.zip"
aws elasticbeanstalk update-environment --application-name my-app --environment-name MyApp-env --version-label 12345
I was looking for this answer as well. I was able to find some AWS documentation that lets you use the Elastic Beanstalk CLI configuration to upload the zip.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-artifact
Deploying an artifact instead of the project folder
You can tell the EB CLI to deploy a ZIP file or WAR file that you generate as part of a separate build process by adding the following lines to .elasticbeanstalk/config.yml in your project folder.
deploy:
artifact: path/to/buildartifact.zip
If you configure the EB CLI in your Git repository, and you don't > commit the artifact to source, use the --staged option to deploy the latest build.
~/eb$ eb deploy --staged
I tested and it did work for me!
I'm attempting to deploy an app from one ElasticBeanstalk instance to another. Running pip install awsebcli --upgrade --user doesnt install the eb cli tool for some odd reason on the EC2 machine.
Does anyone know the equivalent of eb deploy using only the aws cli options?
This question is a bit confusing. Are you attempting to move code between EC2 instances in your Beanstalk environment?
If I'm assuming correctly, you've pulled/changed your code on one Beanstalk host. And now you're trying to propagate that change to the other instances using the EB CLI. That's not a best practice. Beanstalk has a mechanism to deploy your code to all instances.
The EB CLI is meant to be run from your workstation to push code from your IDE/editor to the Beanstalk hosts in AWS.
Beanstalk keeps a copy of that code revision in S3. And if the Beanstalk environment is load balanced then all instances will be running the same application version when scaling events or deployments occur because it will pull your code from a common source.
But to answer your question:
Does anyone know the equivalent of eb deploy using only the aws cli options?
You're gonna wanna ZIP and upload your code to S3 and note the S3 key and bucket values of where it's located.
Then create a new application version.
% aws elasticbeanstalk create-application-version --application-name="<APPLICATION_NAME>" --version-label="<NEW_VERSION_LABEL>" --source-bundle="{\"S3Bucket\": \"<S3_BUCKET_NAME>\",\"S3Key\": \"<S3_KEY>\"}"
Then deploy your new application version to the running environment.
% aws elasticbeanstalk update-environment --environment-id="<ENVIRONMENT_ID>" --version-label="<NEW_VERSION_LABEL>"
Reading is hard...
Linux requires you to "[a]dd the path to the executable file to your PATH variable"
export PATH=~/.local/bin:$PATH
eb --version now works
Is there a way with EB CLI to upload a zip package to the environment but not actually deploy it? This can be done on the web console but I would like to have the output of each build in the CI server to be uploaded to Elastic Beanstalk via EB CLI but only selected builds actually be deployed (this step will be manual in the web console)
The EB CLI does not have the functionality for this process. I would suggest using the AWS CLI to push the local zip into S3 then to upload using the Create Application Version method directly, like this:
aws s3 cp app.zip s3://staging-bucket
aws elasticbeanstalk create-application-version --application-name app-name --version-label deploy-app --source-bundle S3Bucket=staging-bucket,S3Key=app.zip
Does this help your problem?
For a month or so, I've been studying AWS services and now I have to accomplish some basic stuff on AWS elastic beanstalk via command line. As far as I understand there are the aws elasticbeanstalk [command] and the eb [command] CLI installed on the build instance.
When I run eb status inside application folder, I get response in the form:
Environment details for: app-name
Application name: app-name
Region: us-east-1
Deployed Version: app-version
Environment ID: env-name
Platform: 64bit Amazon Linux ........
Tier: WebServer-Standard
CNAME: app-name.elasticbeanstalk.com
Updated: 2016-07-14 .......
Status: Ready
Health: Green
That tells me eb init has been run for the application.
On the other hand if I run:
aws elasticbeanstalk describe-application-versions --application-name app-name --region us-east-1
I get the error:
Unable to locate credentials. You can configure credentials by running "aws configure".
In home folder of current user there is a .aws directory with a credential file containing a [profile] line and aws_access_key_id and
aws_secret_access_key lines all set up.
Beside the obvious problem with the credentials, what I really lack is understanding of the two cli. Why is EB cli not asking for credentials and AWS cli is? When do I use one or the other? Can I use only aws cli? Any clarification on the matter will be highly appreciated.
EDIT:
For anyone ending up here, having the same problem with "Unable to locate credentials". Adding --profile profile-name option solved the problem for me. profile-name can be found in ~/.aws/config (or credentials) file on [profile profile-name] line.
In order to verify that the AWS CLI is configured on your system run aws configure and provide it with all the details it requires. That should fix your credentials problem and checking the change in configuration will allow you to understand what's wrong with your current conf.
the eb cli and the aws cli have very similar capabilities, and I too am a bit confused as to why they both should exist. From my experience the main differences are that the cli is used to interact with your AWS account using simple requests while the eb cli creates connections between you and the eb envs and so allows for finer control over them.
For instance - I've just developed a CI/CD pipeline for our beanstalk apps. When I use the eb cli I can monitor the deployment of our apps and notify the developers when it's finished. aws cli does not offer that functionality, and the only to achieve that is to repeatedly query the service until you receive the desired result.
The AWS CLI is a general tool that works on all AWS resources. It's not tied to a specific software project, the type of machine you're on, the directory you're in, or anything like that. It only needs credentials, whether they've been put there manually if it's your own machine, or generated by AWS if it's an EC2 instance.
The EB CLI is a high level tool to wrangle your software project into place. It's tied to the directory you're in, it assumes that the stuff in your directory is your project, and it has short commands that do a lot of background work to magically put everything in the right place.
I am developing an Elastic Beanstalk app. It is a Scala web application, built with sbt. I want to deploy the resulting WAR from the command line to an existing environment.
All I can find is the eb CLI which appears to require you to use git: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-getting-started.html
Is there not a way to simply specify a WAR and environment name to perform the deployment?
What is the best workaround otherwise? I can upload to S3 from the command line and then use the web app to choose that file, but it's a bit more painful than I wanted.
You can use Elastic Beanstalk CLI (eb) instead of AWS CLI. Just run eb create to create a new environment and eb deploy to update your environment.
You can set specific artifact (your *.war file), by configuring the EB CLI (read: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-artifact):
You can tell the EB CLI to deploy a ZIP or WAR file that you generate
as part of a separate build process by adding the following lines to
.elasticbeanstalk/config.yml in your project folder.
deploy:
artifact: path/to/buildartifact.zip
I found a way - use the aws CLI instead. First upload to S3 (I actually use s3cmd) then create an application version:
$ aws elasticbeanstalk create-application-version --application-name untaggeddb --version-label myLabel --source-bundle S3Bucket="bucketName",S3Key="key.war"
I believe the application version can then be deployed with update-environment also using the aws CLI.