Here is the official tutorial page.
Here is an overview of the tasks.
{}
braces. This part is regarded as variable. E.g. {folder}
.{folder}
You should make your own IAM Role which contains two policies below.
AmazonAPIGatewayPushToCloudWatchLogs
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:PutLogEvents",
"logs:GetLogEvents",
"logs:FilterLogEvents"
],
"Resource": "*"
}
]
}
AmazonS3ReadOnlyAccess
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:Get*",
"s3:List*"
],
"Resource": "*"
}
]
}
In this article, I suppose ReadOnly only API. This role is used for API authorization later.
At API Gateway page in AWS console.
Create a method under /
.
GET
For each API (path, method) pair, we should configure
Here is the simplest config.
/
Content-Type
for 200 status.Contents-Type
as mapping value integration.response.header.Content-Type
.4\d{2}
for 400 response and 500 also.And test it!! Click a TEST at method page.
Here is a sample respose (youBucketName
could be your bucket name.)
Request: /
Status: 200
Latency: 57 ms
Response Body
<?xml version="1.0" encoding="UTF-8"?>
<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Owner>
<ID>716a7854..................</ID>
</Owner>
<Buckets>
<Bucket>
<Name>yourBucketName</Name>
<CreationDate>2020-07-07T12:37:34.000Z</CreationDate>
</Bucket>
</Buckets>
</ListAllMyBucketsResult>
In a nut shell, if your bucket name is foobar
, than the request path should be /foobar
.
Create Resource
/{bucket_name}
, or any name you want, like /{arbitrary}
.Create a method under /{bucket_name}
.
GET
/{bucket}
<- be careful this name. It could be arbitrary.Here is the configuration.
bucket_name
/{bucket}
<- be careful this name.bucket_name
comes from your resource path.x-amz-acl
mapped from 'authenticated-read'
Content-Type
mapped from method.request.header.Content-Type
When no template matches the request Content-Type header
(default)Content-Type
for 200 status.Content-Type
as mapping value integration.response.header.Content-Type
.4\d{2}
for 400 response and 500 also.And test it!! Click a TEST at method page.
Here is a sample respose (youBucketName
could be your bucket name.)
Request: /yourBucketName
Status: 200
Latency: 125 ms
Response Body
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>yourBucketName</Name>
<Prefix />
<Marker />
<MaxKeys>1000</MaxKeys>
<IsTruncated>false</IsTruncated>
<Contents>
<Key>sample2.txt</Key>
<LastModified>2020-07-07T14:06:13.000Z</LastModified>
<ETag>"08397a6f9517bbc8c4be351a8671f941"</ETag>
<Size>23</Size>
<Owner>
<ID>716a7854..................</ID>
</Owner>
<StorageClass>ONEZONE_IA</StorageClass>
</Contents>
<Contents>
<Key>testFolder/</Key>
<LastModified>2020-07-07T12:38:08.000Z</LastModified>
<ETag>"e6a7a7fee872a4564bc3995da1dfcca0"</ETag>
<Size>0</Size>
<Owner>
<ID>716a7854..................</ID>
</Owner>
<StorageClass>STANDARD</StorageClass>
</Contents>
<Contents>
<Key>testFolder/sample.txt</Key>
<LastModified>2020-07-07T12:40:08.000Z</LastModified>
<ETag>"64d29cfdc355e3fea88c486c2455fc14"</ETag>
<Size>23</Size>
<Owner>
<ID>716a7854..................</ID>
</Owner>
<StorageClass>ONEZONE_IA</StorageClass>
</Contents>
</ListBucketResult>
Here is the schematic S3 structure.
yourBucketName
├── sample2.txt
└── testFolder
└── sample.txt
{folder}/{item}
{bucket}
Request: /yourBucketName/sample2.txt
Status: 200
Latency: 173 ms
Response Body
this is a S3 test file.
Custome domain part should be configured.
AmazonS3FullAccess
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": "*"
}
]
}
item
Content-Type
item
, mapped from method.request.path.item
Content-Type
, mapped from method.request.header.Content-Type
Settings -> Binary media types -> Add MIME types, like image/png
, image/jpeg
, application/pdf
, etc.