chore: aws s3 commands examples and lifecycle rules

This commit is contained in:
Michele Cereda
2024-02-10 18:01:13 +01:00
parent cfd52b1860
commit 419b009a23
3 changed files with 128 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
{
"Rules": [
{
"ID": "ExpirationOfTaggedObjects",
"Filter": {
"And": {
"Prefix": "start/here",
"Tags": [
{
"Value": "mytagvalue1",
"Key": "mytagkey1"
},
{
"Value": "mytagvalue2",
"Key": "mytagkey2"
}
]
}
},
"Status": "Enabled",
"Expiration": {
"Days": 1
}
}
]
}

View File

@@ -0,0 +1,17 @@
{
"Rules": [
{
"Filter": {
"Prefix": "oldObjects/"
},
"Status": "Enabled",
"Transitions": [
{
"Days": 365,
"StorageClass": "GLACIER"
}
],
"ID": "TransitionOfOldObjects"
}
]
}

View File

@@ -1,9 +1,85 @@
# Simple Storage Service
1. [TL;DR](#tldr)
1. [Lifecycle configuration](#lifecycle-configuration)
1. [Further readings](#further-readings)
1. [Sources](#sources)
## TL;DR
<details>
<summary>Common usage</summary>
```sh
# List all buckets.
aws s3 ls
# List prefixes and objects in buckets.
# Adding the trailing '/' or '--recurse' lists the content of prefixes.
aws s3 ls 's3://my-bucket'
aws s3 ls 's3://my-bucket/prefix/' --recursive --human-readable --summarize
aws s3 ls 's3://arn:aws:s3:us-west-2:123456789012:accesspoint/myaccesspoint/'
# Create buckets.
aws s3 mb 's3://my-bucket'
# Copy files to or from buckets.
aws s3 cp 'test.txt' 's3://my-bucket/test4.txt'
aws s3 cp 'test.txt' 's3://my-bucket/test2.txt' --expires '2024-10-01T20:30:00Z'
aws s3 cp 's3://my-bucket/test.txt' 'test2.txt'
aws s3 cp 's3://my-bucket/test.txt' 's3://my-bucket/test5.txt'
aws s3 cp 's3://my-bucket/test.txt' 's3://my-other-bucket/'
aws s3 cp 's3://my-bucket' '.' --recursive
aws s3 cp 'myDir' 's3://my-bucket/' --recursive --exclude "*.jpg"
aws s3 cp 's3://my-bucket/logs/' 's3://my-bucket2/logs/' --recursive \
--exclude "*" --include "*.log"
aws s3 cp 's3://my-bucket/test.txt' 's3://my-bucket/test2.txt' \
--acl 'public-read-write'
aws s3 cp 'file.txt' 's3://my-bucket/' \
--grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers \
'full=id=79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be'
aws s3 cp 'mydoc.txt' 's3://arn:aws:s3:us-west-2:123456789012:accesspoint/myaccesspoint/mykey'
# Handling file streams.
aws s3 cp - 's3://my-bucket/stream.txt'
aws s3 cp - 's3://my-bucket/stream.txt' --expected-size '54760833024'
aws s3 cp 's3://my-bucket/stream.txt' -
# Sync buckets.
aws s3 sync '.' 's3://my-bucket'
aws s3 sync 's3://my-bucket' '.' --delete
aws s3 sync 's3://my-bucket' 's3://my-other-bucket' --exclude "*.jpg"
aws s3 sync 's3://my-us-west-2-bucket' 's3://my-eu-east-1-bucket' \
--source-region 'us-west-2' --region 'eu-east-1'
aws s3 sync '.' 's3://arn:aws:s3:us-west-2:123456789012:accesspoint/myaccesspoint/'
# Delete buckets.
aws s3 rb 's3://my-bucket'
aws s3 rb 's3://my-bucket' --force
# Show tags on objects.
aws s3api list-objects-v2 \
--bucket 'my-bucket' --prefix 'someObjectsInHereAreTagged' \
--query 'Contents[*].Key' --output text \
| xargs -n 1 \
aws s3api get-object-tagging --bucket 'my-bucket' --query 'TagSet[*]' --key
```
</details>
<details>
<summary>Lifecycle configurations</summary>
```sh
# Manage lifecycle configurations.
aws s3 get-bucket-lifecycle-configuration --bucket 'batman'
aws s3 put-bucket-lifecycle-configuration --bucket 'batman' \
--lifecycle-configuration 'file://lifecycle-batman.json'
aws s3 delete-bucket-lifecycle --bucket 'batman'
```
</details>
## Lifecycle configuration
When you have multiple rules in an S3 Lifecycle configuration, an object can become eligible for multiple S3 Lifecycle actions. In such cases, Amazon S3 follows these general rules:
@@ -17,14 +93,18 @@ Propagation delay: When you add an S3 Lifecycle configuration to a bucket, there
Objects can only go down the tiers, not up. Many other constraints apply, like no transition done for objects <128KiB.<br/>
See [General considerations for transitions][lifecycle general considerations for transitions].
Examples: [1][lifecycle configuration examples], [2][s3 lifecycle rules examples]
## Further readings
- [Configure notification for lifecycle rules][lifecycle configure notification]
- AWS' [CLI]
### Sources
- [General considerations for transitions][lifecycle general considerations for transitions]
- [Lifecycle configuration examples][lifecycle configuration examples]
- [CLI subcommand reference]
<!--
References
@@ -32,8 +112,13 @@ See [General considerations for transitions][lifecycle general considerations f
<!-- In-article sections -->
<!-- Knowledge base -->
[cli]: cli.md
<!-- Files -->
[s3 lifecycle rules examples]: ../../../examples/aws/s3.lifecycle-rules
<!-- Upstream -->
[cli subcommand reference]: https://docs.aws.amazon.com/cli/latest/reference/s3/
[lifecycle configuration examples]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/lifecycle-configuration-examples.html
[lifecycle configure notification]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/lifecycle-configure-notification.html
[lifecycle general considerations for transitions]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/lifecycle-transition-general-considerations.html