首页 > 解决方案 > Lambda 中的 AWS create_multipart_upload

问题描述

我正在尝试create_multipart_upload在 AWS Lambda 中创建 s3,但它不起作用:

“errorMessage”:“2021-08-30T09:14:04.681Z 5f57321e-f82d-4f3e-95ac-13cfcaba4af1 任务在 30.03 秒后超时”

我更改了 Lambda 函数超时,但结果仍然相同。

我的代码:

import logging
import boto3
import time

from botocore.client import Config
from botocore.exceptions import ClientError

def lambda_handler(event, context):
    
    s3_client = boto3.client('s3', config=Config(signature_version='s3v4'), endpoint_url='https://bucket.enpoint_url')
    
    now_day = time.strftime('%Y-%m-%d', time.localtime(time.time()))
    
    bucket_name='bucket_name'
    
    object_name = now_day + '/' + event['path']
    
    try:
        response = s3_client.create_multipart_upload(Bucket=bucket_name, Key=object_name)
        result = response
        
    except ClientError as e:
        logging.error(e)
        return None
   
    return result

但是如果我在代码中向 generate_presigned_post 发送请求,我通常会收到响应

为什么generate_presigned_post有效create_multipart_upload而不有效?

另外删除端点,create_multipart_upload 也可以。

boto3.client('s3', config=Config(signature_version='s3v4'), endpoint_url='https://bucket.enpoint_url')

->  boto3.client('s3', config=Config(signature_version='s3v4'))

我不知道原因。

标签: amazon-web-servicesaws-lambda

解决方案


推荐阅读