AWS Lambda

From Indie IT Wiki
Jump to: navigation, search

Functions

List Object Uploaded To S3 Bucket

import json
import urllib

def lambda_handler(event, context):
   bucket = event['Records'][0]['s3']['bucket']['name']
   object_key = event['Records'][0]['s3']['object']['key']
   return object_key

Publish To SNS Topic

import json
import urllib
import boto3

def lambda_handler(event, context):
    object_key = event['Records'][0]['s3']['object']['key']
    message = object_key
    sns = boto3.client('sns')
    response = sns.publish(
        TargetArn = 'arn:aws:sns:eu-west-1:292291573537:Topic1',
        Message=json.dumps({'default': json.dumps(message)}),
        MessageStructure='json'
    )
    return object_key