- Newest
- Most votes
- Most comments
To integrate API Gateway with S3 using the GetObject action, you can follow these steps:
-
Create a new API or use an existing one in the API Gateway console.
-
Add a new resource to your API, for example, "/getobject".
-
Create a new method for this resource, typically a GET method.
-
In the method setup:
- Set the Integration Type to "AWS Service"
- Select "S3" as the AWS Service
- Choose "GetObject" as the AWS Action
-
Configure the Integration Request:
- Set the Integration URI to: arn:aws:apigateway:{region}:s3:path/{bucket}/{object} Replace {region} with your AWS region, {bucket} with your S3 bucket name, and {object} will be a placeholder for the object key.
-
Set up a mapping template in the Integration Request section:
-
Add a mapping template for the "application/json" content type
-
Use this template to map request parameters to S3 object metadata:
{ "Bucket": "your-bucket-name", "Key": "$input.params('objectKey')", "VersionId": "$input.params('versionId')" }
Adjust the template based on the metadata you want to use for object retrieval.
-
-
Configure the Method Request:
- Add query string parameters like "objectKey" and "versionId" to pass metadata information
-
Set up the Integration Response to map S3 responses back to your API responses.
-
Create an IAM role for API Gateway with permissions to perform the s3:GetObject action on your bucket.
-
Deploy your API to a stage.
When using this API, clients can make GET requests with query parameters to specify the object metadata, which will be used to retrieve the object from S3.
Remember to handle error cases and ensure proper security measures are in place to protect your S3 data.
Sources
How to integrate API Gateway to S3 Service using Action Type as Action Name PutObject | AWS re:Post
API Gateway call - S3 put object using VTL | AWS re:Post
GetIntegration - Amazon API Gateway
Hello,
keep in mind that API Gateway has a default payload size limit of 10 MB for both requests and responses. This limit can be increased up to 29 MB, but not beyond. For larger files, you can:
- Implement range requests, which allows clients to request specific byte ranges of the object. You'll need to modify your API to accept 'Range' headers and pass them to S3.
- Generate pre-signed URLs for S3 objects and return these URLs to clients instead of the actual object data. Clients can then download directly from S3, bypassing API Gateway size limits
Giulio
Relevant content
- asked a year ago
- AWS OFFICIALUpdated a year ago
Set the Integration URI in Integration Request is confusing in this solution