我正在尝试编写一个 Lambda 函数来将文件从一个 s3 存储桶复制到另一个与 AWS Xray 集成的存储桶。下面是 Lambda 函数的代码。我收到错误
aws_xray_sdk.core.exceptions.exceptions.SegmentNotFoundException:找不到当前段/子段,请确保您有一个段打开
我已将 Aws xray SDK 包含在我的部署包中。此外,代码中还包含开始段和结束段。请给出此错误的解决方案。
import boto3
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch
patch(['boto3'])
client = boto3.client('s3')
s3 = boto3.resource('s3')
SourceBucket = 'bucket1'
DestBucket = 'bucket2'
list1=[];
def lambda_handler(event, context):
response = client.list_objects(Bucket=SourceBucket)
if 'Contents' in response:
for item in response['Contents']:
list1.append(item['Key']);
put_object_into_s3()
for name in list1:
copy_source = {
'Bucket': SourceBucket,
'Key': name
}
response = s3.meta.client.copy(copy_source, DestBucket, name)