Trying Out Various Settings for Amazon S3 Publishing
Tags: aws, amazons3, s3
Published: 2022-01-14 11:08:12

![img](https://day-journal.com/memo/images/logo/aws/s3.png)

### I've been experimenting with various Amazon S3 publishing settings :tada:  

<br>

Advance Preparation

- Amazon S3 bucket creation and file registration

[Amazon S3 #001 - Creating a bucket](https://day-journal.com/memo/amazon-s3-001)

[Amazon S3 #002 - File registration and download](https://day-journal.com/memo/amazon-s3-002)  

<br>

## File Publishing

This is how to publish a file in Amazon S3.  

Click "Edit" in the section of "Block Public Access (Bucket Settings)" under the "Permissions" tab.

![img](https://day-journal.com/memo/images/amazon-s3-003_01.png)

Uncheck "Block All Public Access."

![img](https://day-journal.com/memo/images/amazon-s3-003_02.png)

Since the file will not be published only with these settings, click "Edit" for the bucket policy.

![img](https://day-journal.com/memo/images/amazon-s3-003_03.png)

Configure the bucket policy → Click "Save Changes." This time, we grant permissions to retrieve objects from Amazon S3.

```json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Statement1",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::[Bucket Name]/*"
        }
    ]
}
```

![img](https://day-journal.com/memo/images/amazon-s3-003_04.png)

Make sure that the access permission is set to public.

![img](https://day-journal.com/memo/images/amazon-s3-003_05.png)

The file will be displayed when you access the URL directly.

![img](https://day-journal.com/memo/images/amazon-s3-003_06.png)

<br>

## Publish the File Only to the Specified IP

This is a method to publish files only to specified IPs in Amazon S3. 

Click "Edit" in the section of "Block Public Access (Bucket Settings)" under "Permissions" tab.

![img](https://day-journal.com/memo/images/amazon-s3-004_01.png)

Uncheck "Block All Public Access".

![img](https://day-journal.com/memo/images/amazon-s3-004_02.png)

The file will not be published only with these settings, so click "Edit" for the bucket policy.

![img](https://day-journal.com/memo/images/amazon-s3-004_03.png)

Configure the bucket policy → Click "Save Changes." This time, we grant permissions to retrieve objects from Amazon S3 and access permissions for the specified IP.

```json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Statement1",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::[Bucket Name]/*"
        },
        {
            "Sid": "IP",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::[Bucket Name]/*",
            "Condition": {
                "NotIpAddress": {
                    "aws:SourceIp": "[Allow IP]"
                }
            }
        }
    ]
}
```

![img](https://day-journal.com/memo/images/amazon-s3-004_04.png)

Make sure that the access permission is set to public; it will not be displayed publicly if IP restrictions are set.

![img](https://day-journal.com/memo/images/amazon-s3-004_05.png)

If you access the URL directly from the IP you set, the file will be displayed. The file will not be displayed except for the specified IP.

![img](https://day-journal.com/memo/images/amazon-s3-004_06.png)

<br>

## Public Display of Files Only for Specified Period

This is a method to publish a file only for a specified period of time in Amazon S3.  

Select the target file.

![img](https://day-journal.com/memo/images/amazon-s3-005_01.png)

Click Object Action → Click "Share with signed URL".

![img](https://day-journal.com/memo/images/amazon-s3-005_02.png)

Set the target period → Click "Create signed URL". Accessing the URL copied to the clipboard will confirm that the file will be displayed for the duration.

![img](https://day-journal.com/memo/images/amazon-s3-005_03.png)

<br>

## Static Website Hosting

A note on publishing with Amazon S3's static website hosting.  

Upload a set of HTML and other files that you want to publish.

![img](https://day-journal.com/memo/images/amazon-s3-007_03.png)

Click "Edit" in the section of "Block Public Access (Bucket Settings)" under the "Permissions" tab.

![img](https://day-journal.com/memo/images/amazon-s3-007_04.png)

Uncheck "Block All Public Access."

![img](https://day-journal.com/memo/images/amazon-s3-007_05.png)

This is not enough to make the file public, so click "Edit" under Bucket Policy.

![img](https://day-journal.com/memo/images/amazon-s3-007_06.png)

Configure the bucket policy → Click "Save Changes". This time, we grant permissions to retrieve objects from Amazon S3.

```json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Statement1",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::[Bucket Name]/*"
        }
    ]
}
```

![img](https://day-journal.com/memo/images/amazon-s3-007_07.png)

Make sure that the access permissions are set to public.

![img](https://day-journal.com/memo/images/amazon-s3-007_08.png)

Click "Edit" in the section of "Static Website Hosting" under "Permissions" tab.

![img](https://day-journal.com/memo/images/amazon-s3-007_09.png)

Check "Enable", "Host Static Website", and Set Root HTML → Click "Save Changes".

![img](https://day-journal.com/memo/images/amazon-s3-007_10.png)

Confirm that Static Website Hosting is now enabled; you will be issued a URL to access.

![img](https://day-journal.com/memo/images/amazon-s3-007_11.png)

The WebSite you uploaded will be displayed.

![img](https://day-journal.com/memo/images/amazon-s3-007_12.png)

<br>

It was great to recognize once again that it is possible to set various things with Amazon S3 alone. It is also possible to build it with AWS Amplify, ServerlessFramework, CloudFormation, etc., but it is also important to operate S3 from the AWS Management Console and review the basics :bulb: 

In the next article, I would like to introduce another method that combines Amazon CloudFront.

<br>

Related Articles

{% link https://dev.to/aws-builders/trying-out-various-settings-for-aws-waf-publishing-5c4n %}
{% link https://dev.to/aws-builders/trying-out-various-settings-for-amazon-cloudfront-publishing-28pp %}