Reputation: 346
I am attempting to test this AWS S3 PreSignedURL Lambda Function
import boto3
from botocore.exceptions import ClientError
def lambda_handler(bucket='bg-us-east-1-bucket', key='filename.jpg', expiry=3600):
"""
Method to get post url from s3
:param bucket: name of s3 bucket
:param key: key of the file
:return:
"""
try:
presigned_post = boto3.client('s3').generate_presigned_post(
bucket,
key,
ExpiresIn=expiry
)
return SimpleNamespace(success=True, data={
'upload_url': presigned_post['url'],
'fields': presigned_post['fields']
})
except ClientError:
return SimpleNamespace(
success=False,
error='Unable to upload image'
)
I test with this Test Event:
{
"bucket": "bg-us-east-1-bucket",
"key": "value3"
}
and I get this Execution error response:
"errorMessage": "Parameter validation failed:\nInvalid type for parameter Bucket, value: {'bucket': 'bg-us-east-1-bucket', 'key': 'value3'}, type: <class 'dict'>, valid types: <class 'str'>",
"errorType": "ParamValidationError",
Any suggestions what is causing this AWS Lambda error response?
Upvotes: 0
Views: 64
Reputation: 4014
A handler function is expected to have this signature:
def handler_name(event, context):
So the entire event is passed in as the first parameter, which in your code is used as the bucket parameter for the AWS API code.
https://docs.aws.amazon.com/lambda/latest/dg/python-handler.html
Upvotes: 3