这是我尝试过的。
拉姆达代码:
import uuid
import boto3
def lambda_handler(event, context):
# Get the service client.
s3 = boto3.client('s3')
# Generate a random S3 key name
upload_key = uuid.uuid4().hex
# Generate the presigned URL for put requests
presigned_url = s3.generate_presigned_url(
ClientMethod='put_object',
Params={
'Bucket': 'test',
'Key': upload_key,
'ContentType': 'image/png',
'ACL': 'public-read'
}
)
# Return the presigned URL
return {
"upload_url": presigned_url
}
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<ExposeHeader>ETag</ExposeHeader>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration> …Run Code Online (Sandbox Code Playgroud)