EventBridge Scheduler - Only one out of 4 functions work.

0

I've followed this source - https://repost.aws/knowledge-center/start-stop-lambda-eventbridge

Created four lambda functions, start/stop for two instances.

EventBridge rules setup, with crons and allocated to the lambda functions. Only thing I've noticed is that the stop function for once instance works.

If more information required, happy to share. Just getting annoyed of having to mainly restart/stop. I had functions set in node.js and upgraded them to node.js 18 and they broke so I followed the above source.

질문됨 7달 전218회 조회
2개 답변
1

Hello.

Are there any errors in CloudWatch Logs?
Is it possible for you to share the Lambda code as well?

Also, if you only want to stop and start EC2, I think it would be easier to set up Amazon EventBridge Scheduler without creating Lambda.
The blog below configures Amazon EventBridge Scheduler to stop EC2, but you can configure the settings for starting it using almost the same steps.
https://dev.to/aws-builders/easy-setup-for-ec2-stop-jobs-with-amazon-eventbridge-scheduler-4lpg

profile picture
전문가
답변함 7달 전
  • Thank you for your reply. Looking at the code, there seems to be no problem. It may be a good idea to check the IAM role set for Lambda or the API history of CloudTrail.

0

There's no errors, for one of the functions it has the log of when the server was stopped. But for everything theres no logs at all, only for when a test has been ran.

Start Instance (Removed instance ID)

import boto3
region = 'eu-west-2'
instances = [''] 

ec2 = boto3.client('ec2', region_name=region)

def lambda_handler(event, context):
    ec2.start_instances(InstanceIds=instances)
    print('started your instances: ' + str(instances))

Stop Instance

import boto3
region = 'eu-west-2'
instances = ['']

ec2 = boto3.client('ec2', region_name=region)

def lambda_handler(event, context):
    ec2.stop_instances(InstanceIds=instances)
    print('stopped your instances: ' + str(instances))

I could try use the method you've posted.

답변함 7달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠