Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
025d268
commit 8b71818
Showing
9 changed files
with
90 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.venv/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ var/ | |
*.egg | ||
node_modules/ | ||
.venv/ | ||
__pycache__/ | ||
|
||
# Serverless directories | ||
.serverless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,46 @@ | ||
import json | ||
import base64 | ||
import boto3 | ||
import os | ||
import time | ||
|
||
bucket_name = os.environ['BUCKET_NAME'] | ||
queue_name = os.environ['QUEUE_NAME'] | ||
|
||
|
||
def selfie(event, context): | ||
body = { | ||
"message": "Go Serverless v1.0! Your function executed successfully!", | ||
"input": event | ||
} | ||
body = event['body'] | ||
email = body['email'] | ||
image = base64.b64decode(body['image']) | ||
|
||
# Create S3 client and store image | ||
s3 = boto3.client('s3') | ||
file_name = 'archive/image-'+time.strftime("%Y%m%d-%H%M%S")+'.jpg' | ||
response = s3.put_object(Body=image, Bucket=bucket_name, Key=file_name) | ||
|
||
# Create SQS client and send data for processing | ||
sqs = boto3.client('sqs') | ||
response = sqs.get_queue_url(QueueName=queue_name) | ||
queue_url = response['QueueUrl'] | ||
|
||
# Send message to SQS queue | ||
response = sqs.send_message(QueueUrl=queue_url, MessageBody=body['image'], MessageAttributes={ | ||
'Email': { | ||
'StringValue': email, | ||
'DataType': 'String' | ||
} | ||
}) | ||
|
||
response = { | ||
"headers": { | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Credentials": "true", | ||
}, | ||
"statusCode": 200, | ||
"body": json.dumps(body) | ||
"body": { | ||
"image": "https://s3.amazonaws.com/" + bucket_name + "/" + file_name, | ||
"message_md5": response['MD5OfMessageBody'], | ||
"email": email | ||
} | ||
} | ||
|
||
print(event) | ||
|
||
return response | ||
|
||
# Use this code if you don't use the http event with the LAMBDA-PROXY | ||
# integration | ||
""" | ||
return { | ||
"message": "Go Serverless v1.0! Your function executed successfully!", | ||
"event": event | ||
} | ||
""" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
boto3 | ||
boto3 | ||
Pillow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.