Execute AWS CLI Command
Overview
The Execute AWS CLI Command action allows users to run any AWS CLI command directly from their bot workflow. This feature supports a wide range of AWS operations, providing flexibility in managing AWS resources efficiently. Users can either enter an AWS CLI command manually or use an AI prompt to generate the appropriate command based on specific requirements.
Prerequisites
Linux Agent
- The AWS CLI must be installed and configured on the agent, with credentials that have the appropriate permissions for the intended AWS operations.
- Refer to the AWS CLI installation guide.
How to Use This Action?
To use the Execute AWS CLI Command action, follow these steps:
-
In your bot workflow, navigate to the Linux Actions and select Library.
-
Search for or locate the Execute AWS CLI Command action and drag it into your workflow.
-
Select the Linux integration that is connected to your AWS CLI-configured agent.
-
Under the Parameters section, specify the required parameter values according to your requirements. For more details, refer to the Parameter Details section.
-
In the
aws_command
field, you can either:-
Manually enter the AWS CLI command you want to execute.
-
Use AI to generate the command by clicking on the "Generate with AI" button. For example, enter a prompt like "describe all instances in the us-east-1 region."
-
-
Save or update the bot, then click on the Run button to execute the bot or the Run button inside the action node. Wait for the execution to complete. After execution, view the results in the execution details.
Parameter Details
Parameter | Required | Description |
---|---|---|
aws_command | Yes | The AWS CLI command to execute. |
use_aws_cli_config | Conditional | Indicates whether to use the AWS CLI configuration directly (defaults to True). This method is familiar and quick to set up. Ensure the AWS CLI is installed and configured using aws configure . For advanced options, use config_profile . |
run_as_user | Yes | Specifies the user under which the command runs (defaults to "ubuntu."). Update the username if using a different cloud provider or user. Ensure AWS CLI is configured for this user. |
config_profile | Conditional | The profile from which to load AWS credentials. To use this instead of use_aws_cli_config , add the necessary credentials to the agent configuration file, including AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY , and AWS_DEFAULT_REGION . For more information on the agent configuration file, refer to the Agent Installation Guide. |
execution_timeout | Yes | The maximum time (in seconds) allowed for command execution, defaulting to 300 seconds. |
Example Use Case
Scenario: Stopping All Running EC2 Instances Tagged with Environment=dev
As a cloud administrator, you need to efficiently manage EC2 instances by stopping all instances tagged with Environment=dev
in the us-east-1
region. This command helps streamline resource management and optimize costs by stopping instances no longer needed.
Command to Stop All Running EC2 Instances with a Specific Tag:
Use the following command to locate and stop all running EC2 instances with the Environment=dev
tag in the specified region:
aws ec2 describe-instances \ --region us-east-1 \ --filters "Name=tag:Environment,Values=dev" "Name=instance-state-name,Values=running" \ --query "Reservations[].Instances[].InstanceId" \ --output text | xargs -I {} aws ec2 stop-instances --region us-east-1 --instance-ids {}