Skip to content
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

S3 to S3 Replication in SAM #2062

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ec9210e
S3 to S3 Replication in SAM
jorgetovar Jan 22, 2024
acf7064
S3 to S3 Replication in SAM
jorgetovar Jan 22, 2024
8c8196b
Update s3-s3-replication-sam/README.md
jorgetovar Feb 29, 2024
22d44c6
Update s3-s3-replication-sam/README.md
jorgetovar Feb 29, 2024
e74c8f4
Update s3-s3-replication-sam/example-pattern.json
jorgetovar Feb 29, 2024
73fbd9b
Update s3-s3-replication-sam/example-pattern.json
jorgetovar Feb 29, 2024
304033e
S3 replication
jorgetovar Feb 29, 2024
5717faa
Merge branch 'jorgetovar-feature-s3-replication' of https://github.co…
jorgetovar Feb 29, 2024
08c7e79
Update s3-s3-replication-sam/example-pattern.json
jorgetovar Feb 29, 2024
f360089
Update s3-s3-replication-sam/template.yaml
jorgetovar Feb 29, 2024
7fe5575
S3 replication
jorgetovar Feb 29, 2024
79684c6
Merge branch 'jorgetovar-feature-s3-replication' of https://github.co…
jorgetovar Feb 29, 2024
c695e1d
Update s3-s3-replication-sam/example-pattern.json
jorgetovar Mar 26, 2024
7321c19
Update links and improve how it works
jorgetovar Mar 26, 2024
b5c9cc9
Update example-pattern.json
jorgetovar Apr 17, 2024
6e85a36
Add youtube cross region replication
jorgetovar May 10, 2024
9fbc567
Links to relevant documentation
jorgetovar May 10, 2024
88b3228
Links to relevant documentation
jorgetovar May 10, 2024
ef87e0d
Add final pattern file
bfreiberg May 23, 2024
16de673
Fix service name
bfreiberg May 23, 2024
4c1d55d
Amazon S3 replication name
jorgetovar May 28, 2024
f19d209
Merge branch 'jorgetovar-feature-s3-replication' of https://github.co…
jorgetovar May 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions s3-s3-replication-sam/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# AWS S3 Bucket Replication
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved

This pattern enables you to replicate objects across Amazon S3 buckets, providing a reliable and scalable solution for data redundancy and disaster recovery.

**Key Benefits**:
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved

- **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

Explain how the service interaction works.
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved

## Testing

Provide steps to trigger the integration and show what should be observed if successful.
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved

## Cleanup

1. Delete the stack:
```bash
aws cloudformation delete-stack --stack-name STACK_NAME
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved
```
1. Confirm the stack has been deleted:
```bash
aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"
```

----

Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0
67 changes: 67 additions & 0 deletions s3-s3-replication-sam/example-pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"title": "AWS S3 bucket replication",
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved
"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
"Data Redundancy and Durability: Safeguard against data loss with automatic and asynchronous replication of objects between S3 buckets.",
"Disaster Recovery: Establish a robust disaster recovery strategy by replicating data to different regions or accounts.",
"Global Content Distribution: Reduce latency and enhance user experience by replicating frequently accessed data to various geographical locations.",
"Compliance and Data Retention: Address regulatory standards and compliance requirements by replicating data to separate accounts or regions.",
"Operational Efficiency: Asynchronous replication allows you to focus on other tasks while data is efficiently copied in the background.",
"Cross-Region Replication (CRR): Achieve low-latency access for users in different AWS regions by replicating data across regions.",
"Same-Region Replication (SRR): Ensure redundancy, compliance, or operational efficiency by copying data to a separate bucket within the same region.",
"Cross-Account Replication: Securely share data across AWS accounts by replicating objects to a destination bucket in a different account.",
"Granular Control: Configure replication rules at the bucket level for precise control over which objects to replicate and where.",
"Flexible Implementation: Leverage native S3 replication features to configure replication behavior through JSON-based, structured language."
]

},
"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": "s3-s3-replication-sam.py"
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved
}
},
"resources": {
"bullets": [
{
"text": "Call Athena with Step Functions",
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved
"link": "https://docs.aws.amazon.com/step-functions/latest/dg/connect-athena.html"
},
{
"text": "Amazon Athena - Serverless Interactive Query Service",
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved
"link": "https://aws.amazon.com/athena/"
}
]
},
"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": "www.linkedin.com/in/jorgetovar-sa",
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved
"twitter": "https://twitter.com/jorgetovar621"
}
]
}
97 changes: 97 additions & 0 deletions s3-s3-replication-sam/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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: '*'
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved
- Effect: 'Allow'
Action:
- 's3:ReplicateObject'
- 's3:ReplicateDelete'
- 's3:ReplicateTags'
- 's3:GetObjectVersionTagging'
- 's3:ObjectOwnerOverrideToBucketOwner'

Resource: '*'
jorgetovar marked this conversation as resolved.
Show resolved Hide resolved

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}"