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年前3484ビュー
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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ