S3 Quick Start¶
This guide covers the basic steps required to start using the S3 service.
The examples use the AWS CLI.
Service Information¶
| Setting | Value |
|---|---|
| S3 Endpoint | https://s3.net.de |
| Region | de-han-1 |
| Root profile | my-netde-account-root |
Prerequisites¶
Install the AWS CLI and verify the installation:
You need the following credentials:
- Root access key
- Root secret key
Official AWS documentation:
1. Configure Root Access¶
Configure the AWS CLI profile:
Enter your credentials and region:
AWS Access Key ID: <ROOT_ACCESS_KEY>
AWS Secret Access Key: <ROOT_SECRET_KEY>
Default region name: de-han-1
Default output format: json
Configure the S3 endpoint:
Test the connection:
The root credentials have administrative privileges. Use dedicated IAM users for applications and regular S3 access.
Official AWS documentation:
2. Create IAM Users¶
In this example, two users are created:
| User | Permission |
|---|---|
app-rw |
Read, write and delete |
app-ro |
Read only |
Create the Read/Write User¶
Create an access key:
The response contains an AccessKeyId and SecretAccessKey.
Example:
{
"AccessKey": {
"UserName": "app-rw",
"AccessKeyId": "<ACCESS_KEY>",
"SecretAccessKey": "<SECRET_KEY>",
"Status": "Active"
}
}
Store both values securely.
Create the Read-Only User¶
Create an access key:
Store the returned credentials securely.
Official AWS documentation:
3. Create a Bucket¶
Create a bucket called customer-data:
aws --profile my-netde-account-root s3api create-bucket \
--bucket customer-data \
--region de-han-1
List the available buckets:
Check access to the bucket:
Official AWS documentation:
4. Grant Read/Write Access¶
Create a file named customer-data-rw.json:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BucketAccess",
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::customer-data"
},
{
"Sid": "ObjectAccess",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::customer-data/*"
}
]
}
Attach the policy to app-rw:
aws --profile my-netde-account-root iam put-user-policy \
--user-name app-rw \
--policy-name customer-data-rw \
--policy-document file://customer-data-rw.json
The user can now:
- List objects
- Download objects
- Upload objects
- Delete objects
The permissions apply only to customer-data.
Official AWS documentation:
- IAM
put-user-policy - S3 identity-based policy examples
- S3 actions, resources and condition keys
- IAM policies and permissions
5. Grant Read-Only Access¶
Create a file named customer-data-ro.json:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BucketAccess",
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::customer-data"
},
{
"Sid": "ObjectAccess",
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": "arn:aws:s3:::customer-data/*"
}
]
}
Attach the policy:
aws --profile my-netde-account-root iam put-user-policy \
--user-name app-ro \
--policy-name customer-data-ro \
--policy-document file://customer-data-ro.json
The resulting permissions are:
| Operation | app-rw |
app-ro |
|---|---|---|
| List objects | Yes | Yes |
| Download objects | Yes | Yes |
| Upload objects | Yes | No |
| Delete objects | Yes | No |
Official AWS documentation:
6. Configure the IAM Users¶
Read/Write User¶
Enter:
AWS Access Key ID: <APP_RW_ACCESS_KEY>
AWS Secret Access Key: <APP_RW_SECRET_KEY>
Default region name: de-han-1
Default output format: json
Configure the endpoint:
Read-Only User¶
Enter:
AWS Access Key ID: <APP_RO_ACCESS_KEY>
AWS Secret Access Key: <APP_RO_SECRET_KEY>
Default region name: de-han-1
Default output format: json
Configure the endpoint:
Official AWS documentation:
7. Upload and Download Objects¶
Create a test file:
Upload¶
List¶
Download¶
Delete¶
Official AWS documentation:
8. Test Read-Only Access¶
Make sure a test object exists:
Listing should succeed:
Downloading should succeed:
Uploading should fail with AccessDenied:
Deleting should also fail with AccessDenied:
Official AWS documentation:
9. Bucket Versioning¶
Create another bucket:
aws --profile my-netde-account-root s3api create-bucket \
--bucket customer-archive \
--region de-han-1
Enable versioning:
aws --profile my-netde-account-root s3api put-bucket-versioning \
--bucket customer-archive \
--versioning-configuration Status=Enabled
Check the versioning configuration:
Expected result:
Upload the first version:
echo "Version 1" > example.txt
aws --profile my-netde-account-root s3 cp \
example.txt s3://customer-archive/example.txt
Upload another version:
echo "Version 2" > example.txt
aws --profile my-netde-account-root s3 cp \
example.txt s3://customer-archive/example.txt
List all versions:
Official AWS documentation:
10. Public Read Access¶
Warning: Public access makes objects accessible without authentication. Only enable public access when it is explicitly required.
Create a public bucket:
aws --profile my-netde-account-root s3api create-bucket \
--bucket customer-public \
--region de-han-1
Create a file named public-read.json:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::customer-public/*"
}
]
}
Apply the bucket policy:
aws --profile my-netde-account-root s3api put-bucket-policy \
--bucket customer-public \
--policy file://public-read.json
Upload an object:
echo "Hello World" > public.txt
aws --profile my-netde-account-root s3 cp \
public.txt s3://customer-public/public.txt
The policy grants only:
Anonymous users are not granted permission to:
- List objects
- Upload objects
- Modify objects
- Delete objects
Official AWS documentation:
11. Common S3 Commands¶
List Buckets¶
Create a Bucket¶
List Objects¶
Upload an Object¶
Download an Object¶
Delete an Object¶
Upload a Directory¶
Download a Directory¶
Synchronize a Directory¶
Official AWS documentation:
12. Permission Basics¶
S3 distinguishes between bucket permissions and object permissions.
Bucket Permissions¶
Bucket permissions use:
Common actions:
Object Permissions¶
Object permissions use:
Common actions:
GetObject and ListBucket are separate permissions.
A user may therefore be able to download a known object while not having permission to list the bucket.
Official AWS documentation:
- S3 actions, resources and condition keys
- S3 identity-based policy examples
- Identity-based and resource-based policies
13. Security Recommendations¶
The root credentials should only be used for administrative tasks.
Applications should use dedicated IAM users with restricted permissions.
Recommended practices:
- Do not use root credentials in applications.
- Create dedicated IAM users for applications.
- Grant only the permissions an application requires.
- Restrict IAM policies to specific buckets.
- Use separate access keys for separate applications.
- Store secret keys securely.
- Never commit secret keys to Git repositories.
- Disable or remove access keys that are no longer required.
- Do not make buckets public unless public access is explicitly required.
Official AWS documentation:
Quick Reference¶
| Setting | Value |
|---|---|
| Endpoint | https://s3.net.de |
| Region | de-han-1 |
| Root profile | my-netde-account-root |
| Authentication | Access Key / Secret Key |
Root profile configuration:
Test connectivity:
Official AWS documentation: