S3 file path description

0

Hi All
I'm trying to follow this tutorial: https://medium.com/swlh/upload-binary-files-to-s3-using-aws-api-gateway-with-aws-lambda-2b4ba8c70b8e

I'm not clear about the code line: file_path = 'YOUR_FILE_PATH_HERE'
Is this the path to the S3 folder?
If so, how do I find this, or what is it's format?

code example:
import json
import base64
import boto3
BUCKET_NAME = 'YOUR_S3_BUCKET_NAME_HERE'
def lambda_handler(event, context):
file_content = base64.b64decode(event['content'])
file_path = 'YOUR_FILE_PATH_HERE'
s3 = boto3.client('s3')
try:
s3_response = s3.put_object(Bucket=BUCKET_NAME, Key=file_path, Body=file_content)
except Exception as e:
raise IOError(e)
return {
'statusCode': 200,
'body': {
'file_path': file_path
}
}

Edited by: cloudstartuptech on Oct 6, 2019 3:02 PM

asked 5 years ago3342 views
1 Answer
0
Accepted Answer

Hi,
the value you specify here is the "object name" (i.e. Key) in the S3 bucket. The "object name" can include "folders" as part of the "key".

For example, if you have a bucket called "example-bucket", and you specified

file_path='myDog.jpg' 
s3.put_object(Bucket=BUCKET_NAME, Key=file_path, Body=file_content)

If you viewed your bucket in the AWS S3 console, you would see 'myDog.jpg' as a top level object.
You could also include "folders". For example:

file_path='pets/mydog.jpg'
s3.put_object(Bucket=BUCKET_NAME, Key=file_path, Body=file_content)

Now, if you want to your AWS S3 console, and opened your bucket, you would see a "folder" called pets. If you clicked on the "pets folder", you would then see myDog.jpg.

Hope this helps,
-randy

answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions