-
Notifications
You must be signed in to change notification settings - Fork 820
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
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/InvokeAPIToUploadFile.py
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,23 @@ | ||
import requests | ||
import io | ||
from PIL import Image | ||
import os | ||
|
||
url = "<Your API Gateway URL with Resource value>" | ||
|
||
|
||
#image = Image.open(os.getcwd()+"/webcaptures/Y5DOKA9GXL.png") | ||
image = Image.open("./webcaptures/010.png") | ||
stream = io.BytesIO() | ||
image.save(stream,format="PNG") | ||
image_binary = stream.getvalue() | ||
|
||
APIGatewayKey = "<Your API Gateway Key>" | ||
headers = { | ||
'Content-Type': 'application/png', | ||
'x-api-key': APIGatewayKey | ||
} | ||
|
||
response = requests.request("POST", url, headers=headers, data=image_binary) | ||
|
||
print(response.text) |
28 changes: 28 additions & 0 deletions
28
AWS_FileUpload_To_S3_Bucket_With_API_Gateway_And_Lambda/Lambda.py
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,28 @@ | ||
import json | ||
import base64 | ||
import boto3 | ||
import string | ||
import random | ||
|
||
|
||
|
||
def lambda_handler(event, context): | ||
s3 = boto3.client("s3") | ||
|
||
get_file_content = event["body-json"] | ||
|
||
decode_content = base64.b64decode(get_file_content) | ||
|
||
pic_filename = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10)) | ||
|
||
s3_upload = s3.put_object(Bucket="<Your Bucket Name>",Key=pic_filename+".png",Body=decode_content) | ||
|
||
# TODO implement | ||
|
||
return { | ||
|
||
'statusCode': 200, | ||
|
||
'body': json.dumps('The Object is Uploaded successfully!') | ||
|
||
} |