How can I send a variables from cloudwatch service to Lambda function using SNS Topic

0

I have CloudWatch Alarm the count the traffic if the traffic is below the threshold then to send a notification via SNS message and the SNS message trigger A lambda function, and the lambda function trigger a python code to decrees the ASG Instance number. it works for me when I but hardcoded the ASG name And the CloudWatch name inside the lambda, auto_scaling_group_name = 'PRD-WEB-ADS-ASG' cloudwatch_alarm_name = 'ASG_Traffic_TO_ADS_WEB' but now I want it to be generic and dynamic and I want to send the cloudwatch name and the ASG name from the CloudWatch as a variable the lambda can get, I have tried to google it , it suggest me to configure it on the sns / CloudWatch notification section (but I don't see any way to configure the message in cloud watch and I don't see an action section inside the SNS topic, so please help me what I should do and how to get it to lambda. (what I have to write in lambda if I am using python 3.10 where can I configure the notification inside the CloudWatch and what should I write there, and what should I configure on the SNS topic if I already have lambda to trigger

  • Side note: Why do you want to go through all of these steps you have to manually create instead of just using a scaling policy on the ASG?

1 Antwort
0

The CloudWatch alarm embeds a Json payload in the context when sending the SNS notification, which is automatically extracted to the event variable of the Lambda - did you try reading that information? You should get the alarm name from it at the very least. For example, if you take a look at the following blog post (https://aws.amazon.com/blogs/mt/customize-amazon-cloudwatch-alarm-notifications-to-your-local-time-zone-part-1), you'll see that you can get the alarm name with alarmName=event['detail']['alarmName']

Likewise, you can get from event['detail'] the alarm configuration, which will give you extra information that you may need/want?

profile pictureAWS
Jsc
beantwortet vor 10 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen