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

feita há 5 anos3474 visualizações
1 Resposta
0
Resposta aceita

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

respondido há 5 anos

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas