- Terraform
- AWS CLI configured with appropriate credentials
-
Initialize and apply the Terraform configuration:
cd terraform terraform init terraform apply
Invoke the Lambda function with an event containing the instance_name
key to stop EC2 instances with the specified name.
To trigger your Lambda function, you can use the AWS Management Console or AWS CLI.
- Go to the AWS Management Console.
- Navigate to the Lambda service.
- Select your Lambda function.
- Click on the "Test" button.
- Configure a test event with the following JSON:
{
"instance_name": "your-instance-name"
}
- Click "Create" and then "Test" to invoke the Lambda function.
You can invoke the Lambda function using the AWS CLI with the following command:
aws lambda invoke \
--function-name your-lambda-function-name \
--payload '{"instance_name": "your-instance-name"}' \
response.json