Wow, Thank you very much, I needed exactly that! Great guide and also thanks to Preetika!
I am getting below error while creating lambda function although I followed exactly same steps for creating policy n role:
Request failed with status code 403
Please suggest on it
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
Hi there, I read carefully this article and followed all instructions but I receive this error:
[ERROR] EndpointConnectionError: Could not connect to the endpoint URL: "https://ec2.eu-west-3c.amazonaws.com/"
I am trying to stop an instance on eu-west-3c but no way
Can anyone help me to understanf why ?
Thanks in advance, Vincenzo
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
The Python code is incorrect. There needs to be a return before region
@Dipti you have to choose the created Role in the Lambda function under Permissions
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
Thank you for sharing
Why do I need to have the below code block defined before the start of the function?
region = 'us-west-1'
instances = ['i-12345cb6de4f78g9h', 'i-08ce9b2d7eccf6d26']
ec2 = boto3.client('ec2', region_name=region)
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
This was super helpful and worked as advertised, following the step by step instructions for ca-central-1.
Thanks, Rick
Thanks for the demo and blog. Deployed and tested.
There seems to be some confusion on the trust relationship instructions to allow Lambda / Scheduler to access the manually created role. Following the instructions here gives an error: The execution role you provide must allow AWS EventBridge Scheduler to assume the role.
I think the issue is this step: Under Execution role, choose Use an existing role.
I tried instead to use the option to create a new role. The following was generated
Role: Amazon_EventBridge_Scheduler_LAMBDA_abcdef1234 Trust Relationship { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "scheduler.amazonaws.com" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "aws:SourceAccount": "123456789012" } } } ] }
See https://docs.aws.amazon.com/scheduler/latest/UserGuide/setting-up.html for more info
Hello! Just one error that I found when working with a customer and using this guide. For the code, should be formatted as follows:
import boto3
region = 'us-west-1'
instances = ['i-12345cb6de4f78g9h', 'i-08ce9b2d7eccf6d26']
ec2 = boto3.client('ec2', region_name=region)
def lambda_handler(event, context):
ec2.stop_instances(InstanceIds=instances)
print('stopped your instances: ' + str(instances))
import boto3
region = 'us-west-1'
instances = ['i-12345cb6de4f78g9h', 'i-08ce9b2d7eccf6d26']
ec2 = boto3.client('ec2', region_name=region)
def lambda_handler(event, context):
ec2.start_instances(InstanceIds=instances)
print('started your instances: ' + str(instances))
The region being on the same line as import boto3 was where we were running into errors. Simple fix, but thought I'd share for anyone in the future that maybe didnt catch it at first.
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
can we still consider this solution over Instance Scheduler on AWS ? Will using this approach saves more as compared to built-in Instance Scheduler on AWS? Please suggest.

