-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
40 lines (34 loc) · 1.07 KB
/
Copy pathlambda_function.py
File metadata and controls
40 lines (34 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import json
import boto3
def put_message_in_queue(sqs, key_name, bucketName, QueueName='image_classification_queue'):
Queue_url = sqs.get_queue_url(QueueName=QueueName)['QueueUrl']
response = sqs.send_message(
QueueUrl=Queue_url,
DelaySeconds=10,
MessageAttributes={
'Title': {
'DataType': 'String',
'StringValue': 'image_classification_pipeline'
},
's3_key': {
'DataType': 'String',
'StringValue': key_name,
},
'bucketName': {
'DataType': 'String',
'StringValue': bucketName
},
},
MessageBody=(
'Queue_Data'
)
)
def lambda_handler(event, context):
sqs = boto3.client('sqs')
bucketName = event['Records'][0]['s3']['bucket']['name']
key_name = event['Records'][0]['s3']['object']['key']
put_message_in_queue(sqs, key_name, bucketName)
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}