【问题标题】:AWS Lambda (Python3.8) not able to connect to S3 buckets using RoleAWS Lambda (Python3.8) 无法使用角色连接到 S3 存储桶
【发布时间】:2021-11-04 15:48:36
【问题描述】:

由于某种奇怪的原因,Lambda (Python3.8) 无法使用 Role 连接到 S3 存储桶。它只是返回 Timed Out 错误。它甚至不会抛出任何异常。调用此部分时超时 response = s3.list_buckets()

我什至检查了 Lambda ENI流日志。他们正在返回无数据

但是,相同的设置在另一个项目中起作用。

这是代码示例:

import json
import datetime
import time
import config as cf
import boto3
import botocore
from botocore.exceptions import ClientError

def lambda_handler(event, context):
    try:
        # Retrieve the list of existing buckets
        s3 = boto3.client('s3')
        response = s3.list_buckets()
        
        # Output the bucket names
        print('Existing buckets:')
        for bucket in response['Buckets']:
            print(f'  {bucket["Name"]}')
        
    except Exception as e:
        print("Exception:\n" + str(e))

    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

有人遇到过这样的问题吗?

非常感谢您提供一点帮助/建议,过去 2 天我一直在苦苦挣扎,我必须提交我的工作。

提前致谢。

干杯,

苏曼

【问题讨论】:

标签: python amazon-web-services amazon-s3 aws-lambda


【解决方案1】:

问题是我使用私有子网创建了我的 NAT 网关。我将 NAT 网关更改为公共子网,效果很好。

我不需要 VPC 端点来连接到 S3 或我的 VPC 中的任何其他服务。

【讨论】:

    猜你喜欢
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 2023-01-18
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多