generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 1k
S3 to S3 Replication in SAM #2062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
julianwood
merged 22 commits into
aws-samples:main
from
jorgetovar:jorgetovar-feature-s3-replication
Jun 17, 2024
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ec9210e
S3 to S3 Replication in SAM
jorgetovar acf7064
S3 to S3 Replication in SAM
jorgetovar 8c8196b
Update s3-s3-replication-sam/README.md
jorgetovar 22d44c6
Update s3-s3-replication-sam/README.md
jorgetovar e74c8f4
Update s3-s3-replication-sam/example-pattern.json
jorgetovar 73fbd9b
Update s3-s3-replication-sam/example-pattern.json
jorgetovar 304033e
S3 replication
jorgetovar 5717faa
Merge branch 'jorgetovar-feature-s3-replication' of https://github.co…
jorgetovar 08c7e79
Update s3-s3-replication-sam/example-pattern.json
jorgetovar f360089
Update s3-s3-replication-sam/template.yaml
jorgetovar 7fe5575
S3 replication
jorgetovar 79684c6
Merge branch 'jorgetovar-feature-s3-replication' of https://github.co…
jorgetovar c695e1d
Update s3-s3-replication-sam/example-pattern.json
jorgetovar 7321c19
Update links and improve how it works
jorgetovar b5c9cc9
Update example-pattern.json
jorgetovar 6e85a36
Add youtube cross region replication
jorgetovar 9fbc567
Links to relevant documentation
jorgetovar 88b3228
Links to relevant documentation
jorgetovar ef87e0d
Add final pattern file
bfreiberg 16de673
Fix service name
bfreiberg 4c1d55d
Amazon S3 replication name
jorgetovar f19d209
Merge branch 'jorgetovar-feature-s3-replication' of https://github.co…
jorgetovar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Amazon S3 Bucket Replication | ||
|
|
||
| This pattern demonstrates how to replicate S3 bucket objects to multiple S3 buckets. Implemented with SAM. | ||
|
|
||
| **Key Benefits**: | ||
|
|
||
| - **Data Redundancy and Durability**: | ||
| S3 replication ensures that your data is replicated across multiple S3 buckets, offering redundancy and safeguarding against data loss. | ||
| - **Disaster Recovery**: | ||
| By replicating your data to a different region or account, you establish a robust disaster recovery strategy. In the event of an outage or data corruption, you can quickly restore operations using the replicated data. | ||
| - **Global Content Distribution**: | ||
| Replicate frequently accessed data to different geographical locations, reducing latency and enhancing the user experience for global audiences. | ||
| - **Compliance and Data Retention**: | ||
| Address compliance requirements by replicating data to a separate account or region. This ensures data integrity and facilitates adherence to regulatory standards. | ||
| - **Operational Efficiency**: | ||
| S3 replication operates asynchronously, allowing you to focus on other tasks while data is efficiently copied in the background. | ||
|
|
||
|
|
||
| Learn more about this pattern at Serverless Land Patterns: [https://serverlessland.com/patterns/s3-s3-replication-sam](https://serverlessland.com/patterns/s3-s3-replication-sam) | ||
|
|
||
| **Important**: This application utilizes various AWS services, and there are associated costs after Free Tier usage. Please refer to the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any incurred AWS costs. No warranty is implied in this example. | ||
|
|
||
| ## Requirements | ||
|
|
||
| * [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. Ensure that the IAM user used has sufficient permissions to make necessary AWS service calls and manage resources. | ||
| * [Install and configure AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) | ||
| * [Install Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) | ||
| * [Install AWS Serverless Application Model (AWS SAM)](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) | ||
|
|
||
| ## Deployment Instructions | ||
|
|
||
| 1. Create a new directory, navigate to that directory in a terminal, and clone the GitHub repository: | ||
| ```bash | ||
| git clone https://github.com/aws-samples/serverless-patterns | ||
| ``` | ||
| 1. Change the directory to the pattern directory: | ||
| ```bash | ||
| cd s3-s3-replication-sam | ||
| ``` | ||
| 1. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file: | ||
| ```bash | ||
| sam deploy --guided | ||
| ``` | ||
| 1. During the prompts: | ||
| * Enter a stack name. | ||
| * Enter the desired AWS Region. | ||
| * Allow SAM CLI to create IAM roles with the required permissions. | ||
|
|
||
| Once you have run `sam deploy --guided` mode once and saved arguments to a configuration file (samconfig.toml), you can use `sam deploy` in the future to use these defaults. | ||
|
|
||
| 1. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs used for testing. | ||
|
|
||
| ## How it Works | ||
|
|
||
| S3 replication in the same region involves copying objects from one S3 bucket to another within the same AWS region. When replication is configured, S3 automatically copies objects from the source bucket to the destination bucket, ensuring redundancy and data durability. This process helps in scenarios such as data backup, compliance requirements, and minimizing latency for accessing data. | ||
|
|
||
|
|
||
| ## Testing | ||
|
|
||
| Upload some images to the source bucket, and then check the replication bucket. You should be able to see the same data replicated there. | ||
|
|
||
| ## Cleanup | ||
|
|
||
| 1. Empty buckets | ||
| ```bash | ||
| aws s3 rm s3://BUCKET_NAME_SOURCE --recursive | ||
| aws s3 rm s3://BUCKET_NAME_REPLICA --recursive | ||
|
|
||
| ``` | ||
| 2. Confirm the stack has been deleted: | ||
| ```bash | ||
| sam delete --stack-name STACK_NAME | ||
|
|
||
| ``` | ||
|
|
||
| ---- | ||
|
|
||
| Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
|
||
| SPDX-License-Identifier: MIT-0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| { | ||
| "title": "Amazon S3 bucket replication", | ||
| "description": "This pattern sets up replication between S3 buckets.", | ||
| "language": "Python", | ||
| "level": "200", | ||
| "framework": "SAM", | ||
| "introBox": { | ||
| "headline": "How it works", | ||
| "text": [ | ||
jorgetovar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "This pattern sets up S3 replication between two buckets. The replication configuration is set up in the source bucket, and the destination bucket is set up to receive the replicated objects. The replication configuration is set up to replicate all objects in the source bucket to the destination bucket." | ||
| ] | ||
| }, | ||
| "gitHub": { | ||
| "template": { | ||
| "repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/s3-s3-replication-sam", | ||
| "templateURL": "serverless-patterns/s3-s3-replication-sam", | ||
| "projectFolder": "s3-s3-replication-sam", | ||
| "templateFile": "template.yaml" | ||
| } | ||
| }, | ||
| "resources": { | ||
| "bullets": [ | ||
| { | ||
| "text": "Same Region Replication", | ||
| "link": "https://docs.aws.amazon.com/AmazonS3/latest/userguide/replication.html#srr-scenario" | ||
| } | ||
| ] | ||
| }, | ||
| "deploy": { | ||
| "text": [ | ||
| "sam deploy" | ||
| ] | ||
| }, | ||
| "testing": { | ||
| "text": [ | ||
| "See the GitHub repo for detailed testing instructions." | ||
| ] | ||
| }, | ||
| "cleanup": { | ||
| "text": [ | ||
| "<code>sam delete</code>" | ||
| ] | ||
| }, | ||
| "authors": [ | ||
| { | ||
| "name": "Jorge Tovar", | ||
| "image": "https://avatars.githubusercontent.com/u/21094604?v=4", | ||
| "bio": "Software Architect, passionate about serverless technologies and cloud computing.", | ||
| "linkedin": "jorgetovar-sa", | ||
| "twitter": "https://twitter.com/jorgetovar621" | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| { | ||
| "title": "Amazon S3 bucket replication", | ||
| "description": "This pattern sets up replication between S3 buckets.", | ||
| "language": "Python", | ||
| "level": "200", | ||
| "framework": "SAM", | ||
| "introBox": { | ||
| "headline": "How it works", | ||
| "text": [ | ||
| "This pattern sets up S3 replication between two buckets. The replication configuration is set up in the source bucket, and the destination bucket is set up to receive the replicated objects. The replication configuration is set up to replicate all objects in the source bucket to the destination bucket." | ||
| ] | ||
| }, | ||
| "gitHub": { | ||
| "template": { | ||
| "repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/s3-s3-replication-sam", | ||
| "templateURL": "serverless-patterns/s3-s3-replication-sam", | ||
| "projectFolder": "s3-s3-replication-sam", | ||
| "templateFile": "template.yaml" | ||
| } | ||
| }, | ||
| "resources": { | ||
| "bullets": [ | ||
| { | ||
| "text": "Same Region Replication", | ||
| "link": "https://docs.aws.amazon.com/AmazonS3/latest/userguide/replication.html#srr-scenario" | ||
| } | ||
| ] | ||
| }, | ||
| "deploy": { | ||
| "text": [ | ||
| "sam deploy" | ||
| ] | ||
| }, | ||
| "testing": { | ||
| "text": [ | ||
| "See the GitHub repo for detailed testing instructions." | ||
| ] | ||
| }, | ||
| "cleanup": { | ||
| "text": [ | ||
| "<code>sam delete</code>" | ||
| ] | ||
| }, | ||
| "authors": [ | ||
| { | ||
| "name": "Jorge Tovar", | ||
| "image": "https://avatars.githubusercontent.com/u/21094604?v=4", | ||
| "bio": "Software Architect, passionate about serverless technologies and cloud computing.", | ||
| "linkedin": "jorgetovar-sa", | ||
| "twitter": "https://twitter.com/jorgetovar621" | ||
| } | ||
| ], | ||
| "patternArch": { | ||
| "icon1": { | ||
| "x": 20, | ||
| "y": 50, | ||
| "service": "s3", | ||
| "label": "Source S3 bucket" | ||
| }, | ||
| "icon2": { | ||
| "x": 80, | ||
| "y": 50, | ||
| "service": "s3", | ||
| "label": "Destination S3 bucket" | ||
| }, | ||
| "line1": { | ||
| "from": "icon1", | ||
| "to": "icon2", | ||
| "label": "Replication" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| AWSTemplateFormatVersion: '2010-09-09' | ||
| Transform: 'AWS::Serverless-2016-10-31' | ||
| Description: 'S3 bucket replication' | ||
|
|
||
| Parameters: | ||
|
|
||
| BucketSourceName: | ||
| Description: "Bucket Source Name (must be unique)" | ||
| Type: String | ||
|
|
||
| BucketReplicaName: | ||
| Description: "Bucket Replica Name (must be unique)" | ||
| Type: String | ||
|
|
||
| Resources: | ||
|
|
||
| ReplicationRole: | ||
| Type: 'AWS::IAM::Role' | ||
| Properties: | ||
| AssumeRolePolicyDocument: | ||
| Version: '2012-10-17' | ||
| Statement: | ||
| - Effect: 'Allow' | ||
| Principal: | ||
| Service: 's3.amazonaws.com' | ||
| Action: 'sts:AssumeRole' | ||
| Policies: | ||
| - PolicyName: 'ReplicationPolicy' | ||
| PolicyDocument: | ||
| Version: '2012-10-17' | ||
| Statement: | ||
| - Effect: 'Allow' | ||
| Action: | ||
| - 's3:GetBucketVersioning' | ||
| - 's3:ListBucket' | ||
| - s3:GetReplicationConfiguration | ||
| - s3:GetObjectVersionForReplication | ||
| - s3:GetObjectVersionAcl | ||
| - s3:GetObjectVersionTagging | ||
| - s3:GetObjectRetention | ||
| - s3:GetObjectLegalHold | ||
| Resource: | ||
| - !Sub "arn:aws:s3:::${BucketSource}" | ||
| - !Sub "arn:aws:s3:::${BucketReplica}" | ||
| - Effect: 'Allow' | ||
| Action: | ||
| - 's3:ReplicateObject' | ||
| - 's3:ReplicateDelete' | ||
| - 's3:ReplicateTags' | ||
| - 's3:GetObjectVersionTagging' | ||
| - 's3:ObjectOwnerOverrideToBucketOwner' | ||
| Resource: | ||
| - !Sub "arn:aws:s3:::${BucketSource}" | ||
| - !Sub "arn:aws:s3:::${BucketReplica}" | ||
|
|
||
|
|
||
| BucketSource: | ||
| Type: 'AWS::S3::Bucket' | ||
| Properties: | ||
| VersioningConfiguration: | ||
| Status: 'Enabled' | ||
| ReplicationConfiguration: | ||
| Role: !GetAtt ReplicationRole.Arn | ||
| Rules: | ||
| - Destination: | ||
| Bucket: !GetAtt BucketReplica.Arn | ||
| Prefix: '' | ||
| Status: 'Enabled' | ||
| BucketName: !Ref BucketSourceName | ||
|
|
||
| BucketReplica: | ||
| Type: 'AWS::S3::Bucket' | ||
| Properties: | ||
| VersioningConfiguration: | ||
| Status: 'Enabled' | ||
| BucketName: !Ref BucketReplicaName | ||
|
|
||
| BucketReplicaPolicy: | ||
| Type: AWS::S3::BucketPolicy | ||
| Properties: | ||
| Bucket: !Ref BucketReplica | ||
| PolicyDocument: | ||
| Version: 2012-10-17 | ||
| Statement: | ||
| - Sid: "Object Level Permissions" | ||
| Effect: "Allow" | ||
| Principal: | ||
| AWS: !GetAtt ReplicationRole.Arn | ||
| Action: | ||
| - "s3:ReplicateObject" | ||
| - "s3:ReplicateDelete" | ||
| Resource: !Sub "arn:aws:s3:::${BucketReplica}/*" | ||
| - Sid: "Bucket Level Permissions" | ||
| Effect: "Allow" | ||
| Principal: | ||
| AWS: !GetAtt ReplicationRole.Arn | ||
| Action: | ||
| - "s3:List*" | ||
| - "s3:GetBucketVersioning" | ||
| - "s3:PutBucketVersioning" | ||
| Resource: !Sub "arn:aws:s3:::${BucketReplica}" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.