- Allows you to schedule a CRON job(cloudwatch rule) to perform START, STOP or REBOOT for EC2 INSTANCES for given tag key and its value.
Step 2: Enter Values for the following as per your needs
- Application name [ Stack Name of the application created via AWS Cloudformation]
- EC2CronFunction [ Name of the Lambda Function Name ]
- Action [Supported Values are STOP, START or REBOOT - This is Action that will be performed on fitlered ec2 instances]
- CronSchedule [ Cron Schedule for CloudWatch Event Refer: Link for syntax help ]
- TagKey [ Name of the Tag Key that you want to use in filter]
- TagValue [ Value of the Tag Key that you want to use in filter]
Step 3: Select the check box "I acknowledge that this app creates custom IAM roles" and Click on Deploy
Resources that get created with this deployment are as follows:
- Lambda Function
- Cloud Watch Event
- CloudWatchEventPermission
- IAM Role with default AWSLambdaBasicExecutionRole Policy and below custom policy Policy
{
"Statement": [
{
"Action": [
"ec2:RebootInstances",
"ec2:StartInstances",
"ec2:StopInstances"
],
"Resource": "arn:aws:ec2:us-east-2:013472794367:instance:*",
"Effect": "Allow"
},
{
"Action": [
"ec2:DescribeInstances"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
To use the SAM CLI, you need the following tools.
- SAM CLI - Install the SAM CLI
- Python 3 installed
- Docker - Install Docker community edition
To build and deploy your application for the first time, run the following in your shell:
sam build --use-container
sam deploy --guided
AWS$ sam local invoke --env-vars env.json
This sample code is made available under MIT license. See the LICENSE file.
Like this project? Please give it a ★ on our GitHub! it helps us a lot
Have an idea for a feature to enhance this serverless application? Open an issue or pull request !