代码示例:
使用 Python 作为 Lambda 函数的运行语言,并执行以下代码:
import boto3
s3 = boto3.resource('s3')
bucket = s3.Bucket('your-bucket-name')
def lambda_handler(event, context):
try:
for obj in bucket.objects.all():
print(obj.key)
except Exception as e:
print(e)
raise e
此代码示例会输出 S3 Bucket 中所有的对象键(key)。如果在运行 Lambda 函数时出现'Access Denied”错误,则需要检查是否已给予相应的权限。