How to trigger to create a new EC2 instance by event by using CDK?

0

Hello there, I am writing a AWS CDK app with typescript. When DynamoDB insert data trigger to create a new EC2 instance, with running some script saved on S3 bucket, and then terminate the instance. Now I managed to create a SQS queue, and after data insert into DynamoDB will have a message in this queue by DynamoDB stream feature. I can not figure out how to trigger to create a new EC2 instance? If use Lambda function, how to achive downloading script and running process?

Thanks for help!

1개 답변
-1

Hi,

You will need 2 components to achieve your goal:

  1. CDK to create a trigger on DynamoDb starting a Lambda: full corresponding typescript code at https://dev.to/aws-builders/how-to-trigger-an-aws-lambda-from-a-dynamodb-stream-event-d8
  2. The Lambda starting and stopping the EC2 instance: you have security settings, Lambda code here: https://repost.aws/knowledge-center/start-stop-lambda-eventbridge

So, please, combine both to build you use case.

Best,

Didier

profile pictureAWS
전문가
답변함 8달 전
  • Hi, thanks for the reply. From my understanding about the second step, it starts an existing instance, not creates new one? Because it needs the 'instance-id', which I don't have before instance being created?

  • Hi, I thought that you may want to keep your instance across runs to be faster on start instead of terminating it each time. But, you can replace the start with create (with ad hoc paremeters: instance type, etc.) and the stop with terminate. You will find some sample code on the web easily

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

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

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

관련 콘텐츠