Python Forum
Help with AWS Lambda function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with AWS Lambda function
#1
Hello there,

Thanks in advance for your comments. I am really a beginner in Python and I would really appreciate your help.

I need to create an AWS Lambda function to send a notification every four hours if a specific instance is up and running. I have created the code below, but that does not work at all (I know that probably is very bad code :)). Could you please advise? I would use an AWS CloudWatch event as trigger and an AWS SNS topic to send the notification.

import boto3


def instance_status(event, context):
try:
client = boto3.client('ec2')
r = client.describe_instance_status(InstanceIds=['i-xxxxxxxxxx'])
if r == 16:
sns = boto3.client('sns')
response = sns.publish(
TopicArn='arn:aws:sns:us-east-1:xxxxxxx:xxxxxxx',
Message='The x instance is up and running',
)


Regards,


Thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Add two resultant fields from python lambda function klllmmm 4 906 Jun-06-2023, 05:11 PM
Last Post: rajeshgk
  Writing a lambda function that sorts dictionary GJG 1 2,015 Mar-09-2021, 06:44 PM
Last Post: buran
  translating lambda in function fabs 1 2,148 Apr-28-2020, 05:18 AM
Last Post: deanhystad
  Lambda function recursion error DeadlySocks 1 2,050 Apr-13-2020, 05:09 PM
Last Post: deanhystad
  Lambda function error localsystemuser 3 4,724 Jan-29-2020, 01:43 PM
Last Post: DeaD_EyE
  Lambda function Uchikago 3 2,696 Jul-16-2019, 08:56 AM
Last Post: perfringo
  eval lambda function with restricted context Olivier 7 5,119 Mar-04-2019, 10:45 PM
Last Post: Olivier
  Using a lambda function within another function JChapman 8 5,408 Jan-08-2019, 01:54 PM
Last Post: JChapman
  Write lambda function in pyhhon to coy data from multiple JSON into a single JSON fil anandmn85 2 4,229 Apr-19-2018, 05:56 AM
Last Post: anandmn85
  How do I make an assignment inside lambda function? Standard_user 2 20,003 Nov-13-2016, 05:54 PM
Last Post: Standard_user

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020