1 Answer
- Newest
- Most votes
- Most comments
2
Hi Mike,
Let's see if I can help you!
The error "Content Type is not supported" suggests that while your Canary is trying to log the response body, the built-in CloudWatch Synthetics functionality does not natively support the "text/xml" content type for storing response data.
To retain the XML data from a Canary run, you can consider the following approach:
- Modify your script to manually capture the XML response.
- Within the same script, use the AWS SDK to store the XML data to an S3 bucket.
Here is a Python code:
import boto3
import os
# Initialize the S3 client
s3_client = boto3.client('s3')
# Set the bucket name from an environment variable.
# Make sure to set the 'BUCKET_NAME' environment variable in the AWS Lambda console.
BUCKET_NAME = os.environ['BUCKET_NAME']
def lambda_handler(event, context):
# Assume the XML data comes as a string in the 'xml_data' field of the event.
xml_data = event['xml_data']
# Define the path where the XML file should be saved in S3. Replace 'path/to/your' with your desired path.
object_name = 'path/to/your/xmlfile.xml'
try:
# Upload the XML data to the specified S3 bucket and path.
response = s3_client.put_object(Bucket=BUCKET_NAME, Key=object_name, Body=xml_data, ContentType='text/xml')
return {
'statusCode': 200,
'message': f"XML saved successfully in {BUCKET_NAME}/{object_name}"
}
except Exception as e:
print(e)
return {
'statusCode': 500,
'message': 'Error saving XML to S3'
}
Ensure the necessary IAM permissions are granted to the role associated with the Canary so that it can read and write to the desired S3 bucket.
I'll keep tracking your post to see if you've found a resolution.
answered 9 months ago
Relevant content
- asked 4 years ago
- asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 2 years ago
Thanks Victor! step 2 is a bit unnecessary as you can simply direct the response to the logger as I have done, but your response got me there; thanks again!