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

질문됨 5년 전3474회 조회
1개 답변
0
수락된 답변

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

답변함 5년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠