Cloudwatch event rule for Lambda function

0

Hi everyone,

I want to send trigger to cloudwatch event on successful completion of Lambda function( automated password rotation lambda) to send out the SNS. Please help to select the particular event pattern so that it can be used to trigger SNS.

3개 답변
1

I don't think there are any events detected by EventBridge when a Lambda function completes by default.
So I think we can edit the code to use "put_events" to issue a custom event when the Lambda function terminates.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/events/client/put_events.html

For example, the following code would do it.

import boto3
import json

client = boto3.client('events')

detail = {
    'status': 'Success'
}

response = events.put_events(
    Entries=[
        {
            'Source': 'lambda.amazonaws.com',
            'DetailType': 'FunctionEnd',
            'Detail': json.dumps(detail),
            'EventBusName': 'default' 
        }
    ]
)

In addition, I think we can detect this event by setting the following event pattern to catch this event in EventBridge.

{
  "source": ["lambda.amazonaws.com"],
  "detail-type": ["FunctionEnd"],
  "detail": {
    "status": ["Success"]
  }
}
profile picture
전문가
답변함 일 년 전
0

There are couple of ways you can do this.

  1. You can publish the cloudwatch events (event bridge) from your lambda using this example - https://serverlessland.com/patterns/lambda-eventbridge
  2. You can use step function to orchestrate your workflow. First step invoke your lambda for password rotation , if it is success then publish cloudwatch events (event bridge).
  3. You can directly publish your events to SNS as well using this example - https://serverlessland.com/patterns/lambda-sns
AWS
답변함 일 년 전
0

If your function is invoked asynchronously, you can use Lambda Destinations to send the completion event to SNS, EventBridge, SQS or another Lambda function. If your function is invoked synchronously, you will need to do it yourself in the function itself.

profile pictureAWS
전문가
Uri
답변함 일 년 전

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

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

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

관련 콘텐츠