How to link from AWS API Gateway to S3 without going through Lambda

How to link from AWS API Gateway to S3 without going through Lambda

This is the procedure for linking directly from API Gateway to S3 using S3 proxy, without using Lambda.

GET Method

IAM Role Creation

Create an IAM role with full access to S3.

AWS API GatewayからLambdaを通さずにS3へ連携する方法

Edit the trust relationship as follows

AWS API GatewayからLambdaを通さずにS3へ連携する方法

Copy the role ARN as it will be used later.

Putting the file on S3

Next, we place the file sample.txt in the bucket api-to-s3.

AWS API GatewayからLambdaを通さずにS3へ連携する方法

API Gateway Configuration

Add resources in API Gateway. In this case, the resource path should be in the form of a path parameter. It should look something like {xxx}.

AWS API GatewayからLambdaを通さずにS3へ連携する方法

Add a GET method since it retrieves and displays files from S3.

AWS API GatewayからLambdaを通さずにS3へ連携する方法

Click on “Integration Request.”

Select “AWS Service” for Integration Type.

Specify the AWS region and AWS service respectively, and leave the AWS subdomain blank.

The HTTP method is GET, and the path override is {bucketname}/{objectkey}.

For the execution role, set the IAM role created earlier.

AWS API GatewayからLambdaを通さずにS3へ連携する方法

Add the following to the URL path parameter

名前 マッピング元
bucketname method.request.path.bucketname
objectkey method.request.path.objectkey

AWS API GatewayからLambdaを通さずにS3へ連携する方法

Test with this.

AWS API GatewayからLambdaを通さずにS3へ連携する方法

You can confirm that the file is successfully retrieved and output.

By the way, it is OK to deploy and execute URL.

AWS API GatewayからLambdaを通さずにS3へ連携する方法

PUT Method

Next, PUT via API Gateway to create the body part as a file to S3.

IAM uses the same role as for GET. The same bucket is also used.

Add a PUT method to create the file in S3.

Click on “Integration Request”.

Select “AWS Service” for Integration Type.

Specify the AWS Region and AWS Service respectively, and leave the AWS Subdomain blank.

The HTTP method is PUT, and the path override is {bucketname}/{objectkey}.

For the execution role, set the IAM role created earlier.

AWS API GatewayからLambdaを通さずにS3へ連携する方法

Add the following to the URL path parameter

name mapping source
bucketname method.request.path.bucketname
objectkey method.request.path.objectkey

AWS API GatewayからLambdaを通さずにS3へ連携する方法

Test with this.

AWS API GatewayからLambdaを通さずにS3へ連携する方法

You can confirm that the file has been successfully created.

AWS API GatewayからLambdaを通さずにS3へ連携する方法

コメント

Discover more from 株式会社CONFRAGE ITソリューション事業部

Subscribe now to keep reading and get access to the full archive.

Continue reading

Copied title and URL