in NfwSlackIntegartion/src/slack-lambda.py [0:0]
def lambda_handler(event, context):
logger.info('Raw Lambda event:')
logger.info(event)
slackEndpoint= get_secret ()
logger.debug("Retrived slackEndpoint from ASM")
# Get the object from the event and show its content type
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')
logger.info("bucket:"+bucket )
logger.info("key:"+key )
try:
response = s3.get_object(Bucket=bucket, Key=key)
print("CONTENT TYPE: " + response['ContentType'])
logger.info('S3 object triggered this lambda:')
logger.info(response['ContentType'])
bytestream = BytesIO(response['Body'].read())
got_text = gzip.GzipFile(mode='rb', fileobj=bytestream).read().decode('utf-8')
logger.info(got_text)
post_slack_Message (event, context, slackEndpoint, convertText2Json(got_text))
return response['ContentType']
except Exception as e:
print(e)
print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket))
raise e