- Authors
- Name
- Nguyễn Đức Xinh
- Published on
- Published on
AWS Elastic Beanstalk (EB) CLI: Common Command
AWS Elastic Beanstalk (EB) is a robust Platform as a Service (PaaS) that automates the deployment and scaling of web applications and services developed in languages such as Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker. The Elastic Beanstalk Command Line Interface (EB CLI) is a command-line tool that allows you to programmatically interact with Elastic Beanstalk.
In this article, we'll explore some of the most commonly used EB CLI commands to manage your Elastic Beanstalk environments effectively.
Prerequisites
Before you begin, ensure you have the following:
- AWS Account: You need an AWS account to use Elastic Beanstalk.
- AWS CLI: The AWS Command Line Interface (CLI) enables interaction with AWS services. You can download and install it from the official AWS website.
- EB CLI: A plugin for AWS CLI. Refer to the AWS Elastic Beanstalk CLI Installation Guide .
How EB CLI Works
- The
eb init
command initializes your application and sets up the Elastic Beanstalk configuration directory, including the configuration file. - For most commands, navigate to your application's root directory containing the
.elasticbeanstalk/config.yml
file created during initialization. EB CLI will use this file to interact with Elastic Beanstalk.
Initialize an Elastic Beanstalk Application
Start by initializing your application with the following command:
eb init
This command:
-
Creates an Elastic Beanstalk application.
-
Allows you to configure the region, platform, and default credentials. Example:
eb init
# Specify the platform, profile, region, and app name in one command
eb init -p node.js --profile <your-profile> --region ap-northeast-1 <app-name>
Note:
-
Run this command in your application's root directory.
-
A configuration file
.elasticbeanstalk/config.yml
will be created upon successful execution.
Create a New Environment
Once the application is initialized, create a new environment for deployment:
eb create
You can specify the environment name and type:
eb create my-environment-name
- A Environment configuration file
.elasticbeanstalk/[env-name].env.yml
will be created upon successful execution.
Clone an Environment
Clone a new environment from the current one:
eb clone
# Or specify the environment name
eb clone <environment_name> (-n CLONE_NAME)
List Current Environments
eb list
List Application Versions
eb appversion
Example output:
test-environment Application Name: sample-001
Environment Status: Ready Health Green
Current version # deployed: 3
Deploy Your Application
Deploy your application to an Elastic Beanstalk environment:
eb deploy
This command packages and uploads your application to the specified environment. Use this command whenever you update your code.
Check Environment Status
To view the current status of an environment:
eb status
Example output:
Environment details for: test-environment
Application name: sample-001
Region: ap-northeast-1
Deployed Version: app-241219_170320446983
Status: Ready
Health: Green
View Environment Logs
Fetch logs for debugging:
eb logs
To retrieve all logs locally:
eb logs --all
Update Environment Configuration
Edit environment configurations using:
eb config
Open Environment in Browser
Quickly open the environment's URL in your browser:
eb open
Terminate an Environment
Remove an environment and its associated resources:
eb terminate
Monitor Environment Events
Track environment events in real time:
eb events
View the full event history:
eb events --all
Swap URLs Between Environments
For blue-green deployments, swap URLs between environments:
eb swap
Scale Application Instances
Adjust the number of instances:
eb scale 3
SSH Into EC2 Instances
Connect to an EC2 instance using SSH:
eb ssh
Manage Platform Versions
# List all available platforms
eb platform list
# Show current platform
eb platform show
# Create a custom platform version
eb platform create
# Delete a platform
eb platform delete
Set Default Environment
Set a default environment for commands:
eb use [environment_name]
Conclusion
AWS Elastic Beanstalk's EB CLI simplifies application deployment and management with its powerful commands. Mastering these commands will help you efficiently manage AWS environments and streamline development processes. By leveraging EB CLI, you can save time and focus more on building and improving your applications.