0
votes

My code below is for doing slack notification I tested on normal python3.9 terminal works ok In AWS UI of Lambda :- General configuration - i change duration 15 min no luck Increase RAM for fuction no luck EventBridge (CloudWatch Events): EC2-Alert - i set , so that config ios not issue VPC set to be same EC2 full admin, Admin permission along with AWSLambdaBasicExecutionRole-xxxx is set no luck

Log shows

2022-04-10T12:43:41.739-07:00   {'version': '0', 'id': 'f0b301f6-c7f6-634c-a13d-e48df95b7754', 'detail-type': 'EC2 Instance State-change Notification', 'source': 'aws.ec2', 'account': 'xxx', 'time': '2022-04-10T19:38:41Z', 'region': 'us-east-1', 'resources': ['arn:aws:ec2:us-east-1:xxx:instance/i-xxxx'], 'detail': {'instance-id': 'i-0dccxxxx', 'state': 'pending'}}



2022-04-10T12:47:44.841-07:00   REPORT RequestId: 5097072f-db2a-46ae-85c0-39984277bead Duration: 243102.20 ms Billed Duration: 243000 ms Memory Size: 512 MB Max Memory Used: 16 MB
2022-04-10T12:47:44.841-07:00   2022-04-10T19:47:44.841Z 5097072f-db2a-46ae-85c0-39984277bead Task timed out after 243.10 seconds 

This was the code which was pack with virtual env & request etc was uploaded to s3 & shows up ok

Most possible reason of permission or VPC i think is not case here ..

Below is also correct : handler : slackAlert.send_slack

Any suggestions please

import boto3
import json
import requests

webhook_url = "https://hooks.slack.com/services/T03AWS5EYLU/xxxx/xxxx"


def send_slack(event, context):
  print(str(evebt))
  slack_message = {'text': 'EC2 Stopped'}
  response = requests.post(webhook_url, data=json.dumps(slack_message))
  return response.text 
Is your lambda in a private subnet in your vpc? Do you have NAT gateway in a public subnet?Marcin
Thanks for asking , Lambda is given access to subnet ( both ) to which IG is attached so that also can be ruled out ..Kiran Kumar
That's incorrect then. Lambda must be in private subnets. Those subnets don't have IG.Marcin
Thank you, you were correct, in my case i removed the VPCs from Lambda & i got the messages in slack ! @Marcin Thank you.Kiran Kumar