- Newest
- Most votes
- Most comments
Yes, you can achieve this using a mapping template in the Integration Request settings of your API Gateway. Your approach is on the right track, but needs a few adjustments to work correctly.
Here's an improved version of the mapping template that should solve your problem:
#set($path = $input.params().path.get('proxy'))
#set($filename = $input.params().header.get('Filename'))
#set($computedObjectName = "$path/$filename")
{
"bucket": "s2notificationeventtriggerlambdafunction",
"key": "$computedObjectName"
}
This template does the following:
- It extracts the full path from the 'proxy' parameter, which in your case would be "v1/document/12345678987/page".
- It gets the filename from the 'Filename' header.
- It combines these two to create the computed object name.
To use this template:
- In the Integration Request settings, set the "Content-Type" header to "application/json".
- In the "Mapping Templates" section, add a mapping for "application/json" content-type and paste the above template.
This approach allows you to compute the object key dynamically based on both the path parameters and the header, which meets your requirement of having the final object key as "/v1/document/12345678987/page/Samplefile.txt".
Remember to ensure that your IAM role (api-gateway-upload-to-s3) has the necessary permissions to put objects in the specified S3 bucket.
Also, make sure your API method is configured to receive the 'Filename' header, and that your client is sending this header with the request.
This solution provides flexibility and allows you to construct complex object keys based on various inputs from the API request.
Sources
Integration - Amazon API Gateway
Basic tasks of an API integration request - Amazon API Gateway
PutIntegration - Amazon API Gateway
x-amazon-apigateway-integration.requestParameters object - Amazon API Gateway
Tutorial: Create a REST API as an Amazon S3 proxy - Amazon API Gateway
Relevant content
- asked 6 months ago
- asked 9 months ago
- asked 7 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 months ago
- AWS OFFICIALUpdated 2 months ago
Not Working, getting an error.
Updated the Mapping Template beacuse my proxy path is {objectkey+} and header is X-IntegrationServer-Resource-Name
The error i am getting: (3a3959d6-a182-446c-930b-bb4192223872) Execution failed: URI/URL syntax error encountered in signing process (3a3959d6-a182-446c-930b-bb4192223872) Execution failed due to configuration error: Illegal character in path at index 35: https://s3.us-west-2.amazonaws.com/{bucket}/{key}
Can you please help what could be wrong?