You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VPC内Lambda访问S3超时求助(已配置VPC端点)

排查Lambda部署在VPC内访问S3超时问题

问题描述

我正在搭建一条数据流水线:CSV文件上传至S3存储桶后触发Lambda函数,通过Pandas读取文件并将部分数据写入RDS的MySQL表。

参考AWS官方两篇教程完成配置:

  • S3触发Lambda示例教程
  • Lambda访问RDS教程(VPC前置配置部分)

将Lambda部署在RDS所在的默认VPC内,使用官方测试事件测试时,出现**"Task timed out after 3.00 seconds"**错误。已尝试创建VPC端点并配置允许VPC端点访问的存储桶策略,但问题仍未解决。

已配置的资源与权限

Lambda执行角色策略

  • AWSLambdaVPCAccessExecutionRole
  • AmazonS3FullAccess
  • 自定义策略:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:PutLogEvents",
                "logs:CreateLogGroup",
                "logs:CreateLogStream"
            ],
            "Resource": "arn:aws:logs:*:*:*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": "arn:aws:s3:::*/*"
        }
    ]
}

Lambda函数代码

import json
import urllib.parse
import boto3

print('Loading function')

s3 = boto3.client('s3')


def lambda_handler(event, context):
    print("Received event: " + json.dumps(event, indent=2))

    # Get the object from the event and show its content type
    bucket = event['Records'][0]['s3']['bucket']['name']
    key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')
    
    try:
        response = s3.get_object(Bucket=bucket, Key=key)
        print("CONTENT TYPE: " + response['ContentType'])
        print("Response: ", response)
        
        return response['ContentType']
    except Exception as e:
        print(e)
        print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket))
        raise e

测试事件

使用AWS官方提供的S3触发测试事件示例。

Lambda资源策略

Lambda资源策略

请求帮助

恳请提供排查建议,解决Lambda访问S3超时的问题。

内容的提问来源于stack exchange,提问作者Dr.Fykos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 11:14:53