[LINUX] Let's upload S3 files with CLI

Introduction

You can create S3 on the management console screen, but I haven't created it by operating it with CLI, so I tried this time.

procedure

Check AWS CLI Check if the AWS CLI is installed with the following command.
aws --version

S3 permission settings Click IAM> Roles> Roles for which you want to set permissions. Press the "Attach Policy" button. スクリーンショット 2020-08-03 16.00.51.png Enter s3 in the policy filter and select "Amazon Full Access". Press Attach Policy. スクリーンショット 2020-08-03 16.04.37.png It is displayed that it has been attached. スクリーンショット 2020-08-03 16.09.14.png

Set default region
$ aws configure
AWS Access Key ID [None]: 
AWS Secret Access Key [None]:
Default region name [None]: ap-northeast-1
Default output format [None]: json

Nothing is specified for "AWS Access Key ID [None]:" and "AWS Secret Access Key [None]:".

Create S3 bucket ``` $ aws mb s3://hoge * The hoge part is a duplicate load, so make it unique. $aws s3 ls * Check if the baguette was created. ``` You can also check it on the management console.

Upload files to S3 bucket Upload any image on the internet. In the case of Chrome browser, right-click the image and select "Copy image address". スクリーンショット 2020-08-03 16.19.00.png Create a work directory in your home directory to work with. Download by specifying the image address as an argument with the wget command in the work directory.
$ mkdir ~/work
$ cd ~/work
$ wget https://hogehoge/hogehoge.png

Execute the s3 ls command by specifying the bucket. Check if there is an image.

$ aws s3 ls s3://hoge

You can also check if there is an image on the management console.

Set public access authority from CLI with the following command.

$ aws s3api put-object-acl --acl public-read --bucket filename--key image name(hoge.png)

Check if there is a permission setting in the access control list.

$ aws s3api get-object-acl --bucket filename--key image name(hoge.png)

Click the object URL in the management console and check if the image can be opened. When the above procedure is followed, the image is displayed.

If you press the object URL and it says "Access Denied" and the image is not displayed, click the "Publish" button in the outline of the object and it will be displayed. スクリーンショット 2020-08-03 19.59.35.png

reference Getting Started with Linux Getting Started with AWS

Recommended Posts

Let's upload S3 files with CLI
Upload files with Django
Upload & move GCS files with Go
Use boto to upload / download files to s3.
Upload files to Google Drive with Lambda (Python)
Upload images to S3 with GUI using tkinter
Resize multipart.File type image with golang ~ Upload to S3
File upload with django
S3 uploader with boto
How to upload files to Cloud Storage with Firebase's python SDK
Upload and delete files to Google Cloud Storages with django-storage
Let's play with 4D 4th
Let's play with Amedas data-Part 1
[S3] CRUD with S3 using Python [Python]
Let's run Excel with Python
S3 operation with python boto3
Image upload & customization with django-ckeditor
Let's make Othello with wxPython
Sorting image files with Python (2)
Sort huge files with python
Sorting image files with Python (3)
Let's play with Amedas data-Part 4
Sorting image files with Python
Let's make dice with tkinter
Transfer files with teraterm [Note]
Let's write python with cinema4d.
Integrate PDF files with Python
Reading .txt files with Python
Let's do R-CNN with Sklearn-theano
Let's play with Amedas data-Part 3
Let's play with Amedas data-Part 2
File upload with Flask + jQuery
Handle JSON files with Matlab
Let's build git-cat with Python
Upload multiple files in Flask
[AWS] Search and acquire necessary data from S3 files with S3 Select