Soru

Zorluk: OrtaAPI Development and Integration with Amazon API Gateway

A developer is configuring a REST API in Amazon API Gateway to act as a front-end proxy for downloading images stored in an Amazon S3 bucket. The client will specify the image name using a path parameter named `imageName`. The developer wants to use a direct AWS Service integration to minimize latency and avoid invoking an AWS Lambda function.

Which two steps are required to configure this integration?

  1. Configure an IAM role that allows the `s3:GetObject` action on the target S3 bucket, and set this role as the Execution Role in the Integration Request settings.Cevap
  2. Set the Path Override in the Integration Request to `my-bucket/{image}` and add `image` to the URL Path Parameters mapped from `method.request.path.imageName`.Cevap
  3. C
    Configure a Lambda Authorizer to validate the request and dynamically return the S3 pre-signed URL in the authorizer response context.
  4. D
    Enable Lambda Proxy integration on the method, and write a Lambda function to retrieve the object from S3 using the AWS SDK.
  5. E
    Create a Velocity Template Language (VTL) mapping template for the Integration Request to extract the path parameter and pass it as a JSON payload in the request body.

Cevap

To configure a direct Amazon S3 integration in API Gateway without Lambda, you must set up an IAM execution role that allows the `s3:GetObject` action on the target S3 bucket, configure the Integration Request with a Path Override pointing to the bucket and object key placeholder, and map the method request path parameter to that placeholder in the URL Path Parameters section.
The correct steps involve configuring a direct AWS Service integration using an IAM execution role to authorize API Gateway to retrieve S3 objects, and mapping the client-supplied path parameter to the S3 request path override in the URL Path Parameters configuration.

Adım Adım Çözüm

1
Configure the IAM execution role with necessary permissions.
An IAM role is created with a trust policy allowing API Gateway (`apigateway.amazonaws.com`) to assume it, and a permission policy granting `s3:GetObject` on the bucket resources (`arn:aws:s3:::my-bucket/*`).
API Gateway needs authorization to read objects from the private S3 bucket on behalf of incoming requests.
2
Set up the S3 integration in API Gateway.
The integration type is set to 'AWS Service', the AWS Service is set to 'Simple Storage Service (S3)', the HTTP method is set to 'GET', and the Execution Role is set to the IAM role ARN.
This establishes the direct connection between API Gateway and the Amazon S3 service without needing an intermediary Lambda function.
3
Map the path parameters for the S3 object key.
The Path Override is set to `my-bucket/{image}`, and the `image` parameter is added to URL Path Parameters with the value of `method.request.path.imageName`.
This dynamically resolves the S3 object key based on the client's request path parameter, ensuring the correct file is requested from S3.

Anahtar Kavram

AWS Service integration allows API Gateway to interact directly with other AWS services like Amazon S3 without incurring the latency and cost of a Lambda function, using IAM execution roles and request path overrides.
Bu soruyu puanla