I am trying to write a Lambda function to copy files from one s3 bucket to another integrated with AWS Xray. Below is the code for Lambda function. I am getting the error
aws_xray_sdk.core.exceptions.exceptions.SegmentNotFoundException: cannot find the current segment/subsegment, please make sure you have a segment open
I have included the Aws xray SDK in my deployment package. Also, begin segment and end segment are included in the code. Please give a solution to this error.
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)