Stop / Start EC2 Instance on a schedule: Difference between revisions
From Cramsession
Jump to navigationJump to search
✍️ Verified Author: Mflavell • Click to view professional profile & credentials
(Created page with "= Introduction = This approach depends on three components. * AWS IAM for rights * Lambda to execute the code * Event bridge to execute the lambda code = Setup rights = = Add Lambda functions = = Schedule the functions =") |
|||
| Line 9: | Line 9: | ||
= Setup rights = | = Setup rights = | ||
Create a new policy in the IAM Console. | |||
* Launch the IAM Console | |||
* Click '''Policies''' | |||
* Click '''Creare policy''' | |||
* Select '''JSON''' (Blue button, top right) | |||
* edit the section and paste the following between the square brackets in the statement. | |||
<code> | |||
{ | |||
"Version": "2012-10-17", | |||
"Statement": [ | |||
{ | |||
"Effect": "Allow", | |||
"Action": [ | |||
"logs:CreateLogGroup", | |||
"logs:CreateLogStream", | |||
"logs:PutLogEvents" | |||
], | |||
"Resource": "arn:aws:logs:*:*:*" | |||
}, | |||
{ | |||
"Effect": "Allow", | |||
"Action": [ | |||
"ec2:Start*", | |||
"ec2:Stop*" | |||
], | |||
"Resource": "*" | |||
} | |||
] | |||
} | |||
</code> | |||
= Add Lambda functions = | = Add Lambda functions = | ||
= Schedule the functions = | = Schedule the functions = | ||
Revision as of 03:15, 29 March 2025
Introduction
This approach depends on three components.
- AWS IAM for rights
- Lambda to execute the code
- Event bridge to execute the lambda code
Setup rights
Create a new policy in the IAM Console.
- Launch the IAM Console
- Click Policies
- Click Creare policy
- Select JSON (Blue button, top right)
- edit the section and paste the following between the square brackets in the statement.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Effect": "Allow",
"Action": [
"ec2:Start*",
"ec2:Stop*"
],
"Resource": "*"
}
]
}