- Newest
- Most votes
- Most comments
Hi,
You may have special characters in the content of variable for the object key that may create such issue leading to an illegal URL
If it's the case, you may need to escape those chars as explained on: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html with the example below
{
"name" : "$input.params('name')",
"body" : $util.escapeJavaScript($input.json('$'))
}
I'd also advise to log your input in details via logging templates to easily spot those errors when they happen during production: see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference
Best,
Didier
The error you're encountering suggests that the placeholders {bucket} and {key} in your S3 URL are not being properly replaced with actual values. This issue is likely caused by a problem in how the integration request is set up or how the mapping template is being applied. Here are a few potential reasons and solutions to consider:
-
Integration Request Configuration: Make sure that in your API Gateway integration request, you have correctly set up the path parameters. The path override should be something like /{bucket}/{key} rather than {bucket}/{key}. The leading slash is important.
-
Mapping Template: Your mapping template looks mostly correct, but there might be an issue with how it's being applied. Ensure that the Content-Type header in your request matches exactly what you've set in the mapping template configuration (application/octet-stream in this case).
-
Variable Names: Verify that the variable names in your mapping template ($path, $filename, etc.) match exactly with the names of the path parameters and headers you're sending in the request.
-
URL Encoding: While you're using $util.urlEncode() for the key, make sure this encoding is being applied correctly. You might want to try encoding the entire path, including the bucket name.
-
API Gateway Stage Variables: If you're using stage variables for the bucket name, ensure they are properly set and referenced.
-
Permissions: Although not directly related to this specific error, ensure that your API Gateway has the necessary permissions to interact with the S3 bucket.
To troubleshoot, you can try the following:
-
Use $input.json('The error you're encountering suggests that the placeholders {bucket} and {key} in your S3 URL are not being properly replaced with actual values. This issue is likely caused by a problem in how the integration request is set up or how the mapping template is being applied. Here are a few potential reasons and solutions to consider:
-
Integration Request Configuration: Make sure that in your API Gateway integration request, you have correctly set up the path parameters. The path override should be something like /{bucket}/{key} rather than {bucket}/{key}. The leading slash is important.
-
Mapping Template: Your mapping template looks mostly correct, but there might be an issue with how it's being applied. Ensure that the Content-Type header in your request matches exactly what you've set in the mapping template configuration (application/octet-stream in this case).
-
Variable Names: Verify that the variable names in your mapping template ($path, $filename, etc.) match exactly with the names of the path parameters and headers you're sending in the request.
-
URL Encoding: While you're using $util.urlEncode() for the key, make sure this encoding is being applied correctly. You might want to try encoding the entire path, including the bucket name.
-
API Gateway Stage Variables: If you're using stage variables for the bucket name, ensure they are properly set and referenced.
-
Permissions: Although not directly related to this specific error, ensure that your API Gateway has the necessary permissions to interact with the S3 bucket.
To troubleshoot, you can try the following:
- Use $input.json('$') in your mapping template to log the entire input, which can help you verify the incoming data.
- Double-check all your API Gateway settings, especially in the Integration Request section.
- Test your API using the API Gateway console to isolate whether the issue is with the API configuration or with how you're calling the API.
If the issue persists after checking these points, you may need to review your overall API Gateway configuration and how it's interacting with S3.#39;) in your mapping template to log the entire input, which can help you verify the incoming data. 2. Double-check all your API Gateway settings, especially in the Integration Request section. 3. Test your API using the API Gateway console to isolate whether the issue is with the API configuration or with how you're calling the API.
If the issue persists after checking these points, you may need to review your overall API Gateway configuration and how it's interacting with S3.
Sources
Configure CORS in Amazon S3 | AWS re:Post
CreateStage - Amazon API Gateway
Relevant content
- asked 6 months ago
- asked 7 months ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago