Use S3 lifecycle rules to change the class of objects
The following pages dealt with object expiration in S3 lifecycle rules.
In this article, we will see how to change the storage class of an object using S3 lifecycle rules.
Transition actions – These actions define when objects transition to another storage class. For example, you might choose to transition objects to the S3 Standard-IA storage class 30 days after creating them, or archive objects to the S3 Glacier Flexible Retrieval storage class one year after creating them.
Managing your storage lifecycle
Environment
Create an S3 bucket.
Sets the bucket lifecycle rules.
Rule to migrate the object’s storage class.
Migrate the class to S3 Intelligent-Tiering one day after the object is placed in the bucket.
CloudFormation template files
The above configuration is built with CloudFormation.
The CloudFormation template is placed at the following URL
https://github.com/awstut-an-r/awstut-soa/tree/main/06/001
Explanation of key points of template files
S3 bucket
Resources:
Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName: !Ref Prefix
LifecycleConfiguration:
Rules:
- Id: !Sub "${Prefix}-Lifecyclerule"
Status: Enabled
Transitions:
- StorageClass: !Ref StorageClass
TransitionInDays: !Ref TransitionInDays
Code language: YAML (yaml)
Lifecycle rules are configured with the LifecycleConfiguration property.
The storage class transitions in the lifecycle rules can be set with the Transitions property.
Specify the storage class to migrate to in the StorageClass property.
In this case, specify “INTELLIGENT_TIERING” to migrate to S3 Intelligent-Tiering.
Specify the number of days until the transition in the TransitionInDays property.
In this case, we specify “1” and set the storage class to transition one day after the object is placed.
Architecting
Use CloudFormation to build this environment and check its actual behavior.
Create CloudFormation stacks and check the resources in the stacks
Create CloudFormation stacks.
For information on how to create stacks and check each stack, please see the following page.
After reviewing the resources in each stack, information on the main resources created in this case is as follows
- S3 bucket: soa-06-001
Check the S3 bucket lifecycle rules from the AWS Management Console.
Surely a lifecycle rule has been created.
Certainly a migration rule has been created.
The content is to migrate the storage class to S3 Intelligent-Tiering one day after the object is installed..
Operation Check
Object Installation
Now that we are ready, we first create an object for testing.
$ dd if=/dev/zero of=./hoge.txt bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.00095441 s, 1.1 GB/s
$ ls -lh ./hoge.txt
-rw-rw-r-- 1 ec2-user ec2-user 1.0M Dec 5 10:46 ./hoge.txt
Code language: Bash (bash)
1MB file.
This is to comply with the following specification.
When you transition objects from the S3 Standard or S3 Standard-IA storage classes to S3 Intelligent-Tiering, S3 Standard-IA, or S3 One Zone-IA, the following object size constraints apply:
Objects smaller than 128 KiB – For the following transitions, Amazon S3 does not transition objects that are smaller than 128 KiB
Transitioning objects using Amazon S3 Lifecycle
Upload this file to the S3 bucket.
$ aws s3 cp ./hoge.txt s3://soa-06-001/
upload: ./hoge.txt to s3://soa-06-001/hoge.txt
Code language: Bash (bash)
Access the bucket again to check the status of the object.
The object is indeed uploaded.
The Storage class column shows that the storage class for this object is Standard.
After applying life cycle rules
One day after the object upload, check the bucket again.
Storage class is now “Intelligent-Tiering”.
The lifecycle rule has indeed changed the class Storage.
Summary
We have identified how to change the storage class of an object using S3 lifecycle rules.