AWS EC2からS3へアクセスする方法

2023年9月7日

環境
AWS EC2 S3

操作方法
1.IAMユーザーを作成する
1).検索入力欄で「IAM」と入力し、「IAM」をクリックします。

2).左の画面で「ユーザー」をクリックし、「ユーザーを追加」ボタンをクリックします。

3).ユーザー名例s3userを入力します。

4).種類「アクセスキー・プログラムによるアクセス」にチェックを入れます。
「次のステップ:アクセス権限」ボタンをクリックします。

5).「既存のポリシーを直接アタッチ」をクリックし、入力欄にs3を入力して検索します。
「AmazonS3FullAccess」にチェックを入れます。
「次のステップ:タグ」→「次のステップ:確認」→「ユーザーの作成」ボタンをクリックしてユーザーを作成します。

6)..csvのダウンロードでファイルをダウンロードして保存します。
ファイルの中にアクセスキーとシークレットキーが記載されています。

2.VPCエンドポイントを作成する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
).検索入力欄で「VPC」と入力し、表示された「VPC」をクリックします。
).左の画面で「エンドポイント」をクリックし、「エンドポイントを作成」をクリックします。
).エンドポイントの名前例endpointAタグを入力します。サービスカテゴリは「AWSのサービス」を選択します。
4).検索欄でS3と入力し、Gatewayタイプのサービス名を選択します。
5).作成したVPCを選択します。
6).作成したルートテーブルを選択します。
「エンドポイントの作成」をクリックするとエンドポイントが作成されます。
1).検索入力欄で「VPC」と入力し、表示された「VPC」をクリックします。 2).左の画面で「エンドポイント」をクリックし、「エンドポイントを作成」をクリックします。 3).エンドポイントの名前例endpointAタグを入力します。サービスカテゴリは「AWSのサービス」を選択します。 4).検索欄でS3と入力し、Gatewayタイプのサービス名を選択します。 5).作成したVPCを選択します。 6).作成したルートテーブルを選択します。 「エンドポイントの作成」をクリックするとエンドポイントが作成されます。
1).検索入力欄で「VPC」と入力し、表示された「VPC」をクリックします。

2).左の画面で「エンドポイント」をクリックし、「エンドポイントを作成」をクリックします。

3).エンドポイントの名前例endpointAタグを入力します。サービスカテゴリは「AWSのサービス」を選択します。

4).検索欄でS3と入力し、Gatewayタイプのサービス名を選択します。

5).作成したVPCを選択します。

6).作成したルートテーブルを選択します。
「エンドポイントの作成」をクリックするとエンドポイントが作成されます。

3.EC2のコンソールでキーを割り当てる
1).Tera TermのSSHでEC2に接続します。

2).コンソールでaws configureで設定を行います。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[ec2-user@ip-10-0-10-4 ~]$ aws configure
AWS Access Key ID [None]: アクセスキー
AWS Secret Access Key [None]: シークレットキー
Default region name [None]: ap-northeast-1
Default output format [None]:
[ec2-user@ip-10-0-10-4 ~]$ aws configure AWS Access Key ID [None]: アクセスキー AWS Secret Access Key [None]: シークレットキー Default region name [None]: ap-northeast-1 Default output format [None]:
[ec2-user@ip-10-0-10-4 ~]$ aws configure
AWS Access Key ID [None]: アクセスキー
AWS Secret Access Key [None]: シークレットキー
Default region name [None]: ap-northeast-1
Default output format [None]:

■ EC2のコンソールからS3のファイルを参照する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[ec2-user@ip-10-0-10-4 ~]$ aws s3 ls
2023-06-12 15:35:34 test-s3-data-2023
[ec2-user@ip-10-0-10-4 ~]$ aws s3 ls s3://test-s3-data-2023
2023-06-13 16:36:42 774 aws-test1.png
2023-06-21 15:10:39 16 test.txt
[ec2-user@ip-10-0-10-4 ~]$
[ec2-user@ip-10-0-10-4 ~]$ aws s3 ls 2023-06-12 15:35:34 test-s3-data-2023 [ec2-user@ip-10-0-10-4 ~]$ aws s3 ls s3://test-s3-data-2023 2023-06-13 16:36:42 774 aws-test1.png 2023-06-21 15:10:39 16 test.txt [ec2-user@ip-10-0-10-4 ~]$
[ec2-user@ip-10-0-10-4 ~]$ aws s3 ls
2023-06-12 15:35:34 test-s3-data-2023
[ec2-user@ip-10-0-10-4 ~]$ aws s3 ls s3://test-s3-data-2023
2023-06-13 16:36:42 774 aws-test1.png
2023-06-21 15:10:39 16 test.txt
[ec2-user@ip-10-0-10-4 ~]$

■ aws s3 cpでS3のバケット内のファイルをEC2に転送します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[ec2-user@ip-10-0-10-4 ~]$ aws s3 cp s3://test-s3-data-2023/test.txt /home/ec2-user
download: s3://test-s3-data-2023/test.txt to ./test.txt
[ec2-user@ip-10-0-10-4 ~]$ more test.txt
hello world study skill
[ec2-user@ip-10-0-10-4 ~]$ aws s3 cp s3://test-s3-data-2023/test.txt /home/ec2-user download: s3://test-s3-data-2023/test.txt to ./test.txt [ec2-user@ip-10-0-10-4 ~]$ more test.txt hello world study skill
[ec2-user@ip-10-0-10-4 ~]$ aws s3 cp s3://test-s3-data-2023/test.txt /home/ec2-user
download: s3://test-s3-data-2023/test.txt to ./test.txt
[ec2-user@ip-10-0-10-4 ~]$ more test.txt
hello world study skill

 

 

AWS

Posted by arkgame