Lab complete!
Now that you have completed this lab, make sure to update your Well-Architected review if you have implemented these changes in your workload.
Click here to access the Well-Architected Tool
In the previous section, we learnt how to enable S3 Intelligent-Tiering through a lifecycle rule for a single bucket. In real-world scenarios, customers may accumulate petabytes of objects in the S3 Standard storage class across tens to hundreds of buckets and in multiple accounts who look for an easier approach to apply a single S3 Lifecycle configuration across multiple buckets to transition data from S3 Standard tier to S3 Intelligent-Tiering.
In this lab, we are going to create a AWS CloudFormation stack which will deploy a Lambda function with IAM permissions to create S3 lifecycle policy rules and to put objects in S3 bucket. Following is a high level logic of the fuction:
IF (lifecycle policy already exist on the bucket)
THEN Skip the bucket
ELSE Create a new policy to transition objects to S3 Intelligent Tiering and attach the policy to the bucket
ENDIF;
The lambda function does not modify Amazon S3 buckets with existing lifecycle policies. But you can customize this lambda function to modify existing S3 lifecycle policy by adding logic in the placeholder Additional customization.
Amazon S3 lifecycle policy defined in the the lambda function creates a rule to move all the existing objects in all the AWS S3 buckets in a given account to S3 Intelligent Tiering Storage Class on the day 0 of object creation/upload. You can customize this logic to define your own transition rule statements. You can refer to some customization examples here.
Download the s3lifecycle-automation.yaml CloudFormation template to your machine.
Go to the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation and click Create Stack > With new resources
Leave Prepare template setting as-is
Click Next
For Stack name use S3TieringLifecycleAutomation
Parameters
Look over the Parameters and their default values.
BucketNameParam - Name of the pre-existing bucket where you like to store automation results.
Click Next
For Configure stack options we recommend configuring tags, which are key-value pairs, that can help you identify your stacks and the resources they create. For example, enter Owner in the left column which is the key, and your email address in the right column which is the value. We will not use additional permissions or advanced options so click Next. For more information, see Setting AWS CloudFormation Stack Options.
For Review
This will take you to the CloudFormation stack status page, showing the stack creation in progress.
When it shows status CREATE_COMPLETE, then you are finished with this step.
Trigger Lambda Function
Once the stack is deployed successfully, Go to Resources tab on cloudformation stacks page and find AWS Lambda function deployed. Click on the Physical ID to navigate to the function in AWS Lambda console
In the Lambda console, click on Test to create a test event.
Specify a name for your test event, keep everything else to default and click Save.
Before running the event, review the lambda function code for any customization as suggested above. Run Test.
Review the execution log to see if the function has been executed successfully. It will generate the output file in the Amazon S3 bucket you specified during cloudformation stack creation.
Once the lambda function execution is successful, go back to S3 console and verify the bucket lifecycle policies created.
You can also deploy this cloudformation template as a stack set if you wish to run this across multiple accounts within your organization. More information around AWS Clouformation Stack set deployment can be found here.
You can also run this exercise at scale via AWS CLI using S3 commands such as ListBuckets followed by PutLifecycleConfiguration to enable lifecycle policy on Amazon S3 buckets. For information on setting up AWS CLI on your machine please refer to the CLI documentation.
Refer to the following link for more details: https://github.com/aws-samples/automated-lifecycle-transition-rules-to-s3int/
Now that you have completed this lab, make sure to update your Well-Architected review if you have implemented these changes in your workload.
Click here to access the Well-Architected Tool