Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

amazon web services - AWS S3 PreSignedURL Lambda Function Test Error

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:
Invalid 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?

question from:https://stackoverflow.com/questions/65893377/aws-s3-presignedurl-lambda-function-test-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...