【发布时间】:2020-12-21 19:49:41
【问题描述】:
我正在尝试验证是否通过 Lambda 函数检查了我的存储桶 mypublicbucketname 的公共访问块。为了进行测试,我创建了一个存储桶,并取消了公共访问块。所以,我做了这个 Lambda:
import sys
from pip._internal import main
main(['install', '-I', '-q', 'boto3', '--target', '/tmp/', '--no-cache-dir', '--disable-pip-version-check'])
sys.path.insert(0,'/tmp/')
import json
import boto3
import botocore
def lambda_handler(event, context):
# TODO implement
print(boto3.__version__)
print(botocore.__version__)
client = boto3.client('s3')
response = client.get_public_access_block(Bucket='mypublicbucketname')
print("response:>>",response)
我更新了最新版本的 boto3 和 botocore。
1.16.40 #for boto3
1.19.40 #for botocore
即使我上传了它们并且功能似乎正确,我也得到了这个异常:
[ERROR] ClientError: An error occurred (NoSuchPublicAccessBlockConfiguration) when calling the GetPublicAccessBlock operation: The public access block configuration was not found
谁能解释我为什么会出现这个错误?
【问题讨论】:
-
我可以确认您的结果。在 AWS Lambda 之外运行代码 运行良好(我使用的是 boto3 1.16.35),但在 内 Lambda 运行它(使用各种版本的 boto3)总是会产生一个 @ 987654326@回复。匹配的
put_public_access_block()工作正常,只是似乎影响了get_public_access_block()。我无法理解为什么 API 调用在 AWS Lambda 下会以不同的方式运行。有趣的是,如果我包含import logging / boto3.set_stream_logger("", logging.DEBUG),在 Lambda 下的调试信息比在 Lambda 之外运行它少。 -
我建议您在github.com/boto/boto3/issues 上提出错误报告——虽然问题似乎与在 AWS Lambda 下运行有关,但很可能与 boto3/botocore 中的某些东西有关。请在此处发布该问题的链接,以便我们关注它。
标签: amazon-web-services amazon-s3 aws-lambda boto3