Skip to content

Commit 504d85d

Browse files
authored
Merge pull request #2831 from kiranram/kiranram-feature-dynamodb-glue-s3-integration
New pattern - terraform-dynamodb-glue-s3
2 parents 624c9e9 + f39ed18 commit 504d85d

9 files changed

Lines changed: 544 additions & 0 deletions

File tree

264 KB
Loading
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Amazon DynamoDB to S3 with zero-ETL using AWS Glue with Terraform
2+
3+
This pattern demonstrates how to create a zero-ETL integration between Amazon DynamoDB and Amazon S3 using AWS Glue transformation job. The AWS Glue job copies data in the specified format, which can be queried using Amazon Athena.
4+
5+
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/dynamodb-glue-s3-terraform
6+
7+
Important: This application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
8+
9+
## Requirements
10+
11+
* [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. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
12+
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
13+
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
14+
* [Terraform](https://www.terraform.io/) installed
15+
16+
## Deployment Instructions
17+
18+
1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
19+
```
20+
git clone https://github.com/aws-samples/serverless-patterns
21+
```
22+
2. Change directory to the pattern directory:
23+
```
24+
cd dynamodb-glue-s3-terraform
25+
```
26+
3. Run below terraform commands to deploy to your AWS account in the desired region (default is us-east-1):
27+
```
28+
terraform init
29+
terraform validate
30+
terraform plan -var aws_region=<YOUR_REGION>
31+
terraform apply -var aws_region=<YOUR_REGION>
32+
```
33+
34+
## How it works
35+
36+
This Terraform pattern creates zero-ETL integration that automatically exports DynamoDB data to S3 using AWS Glue. The AWS Glue job reads from the Amazon DynamoDB table and writes the data in the specified format (currently specified as Parquet in the script) to an encrypted Amazon S3 bucket for potential use in analytics and/or for long-term storage. The entire infrastructure is provisioned with the required IAM permissions, and includes automated testing script to validate the data pipeline functionality.
37+
38+
![pattern](Images/pattern.png)
39+
40+
## Testing
41+
42+
After deployment, run ./test.sh. This script adds rows to Amazon DynamoDB database and triggers the AWS Glue job. Once the job is complete, check Amazon S3 for the target files.
43+
44+
## Cleanup
45+
46+
1. Delete the stack
47+
```
48+
terraform destroy -var aws_region=<YOUR_REGION>
49+
```
50+
----
51+
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
52+
53+
SPDX-License-Identifier: MIT-0
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"title": "Amazon DynamoDB and Amazon S3 zero-ETL integration using AWS Glue",
3+
"description": "Create a Amazon DynamoDB and S3 bucket and integrate them using an AWS Glue job for zero-ETL data transfer.",
4+
"language": "Python",
5+
"level": "200",
6+
"framework": "Terraform",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"This pattern sets up Amazon DynamoDB and Amazon S3 buckets, and integrates them with an AWS Glue job. Using this setup, you can move data from Amazon DynamoDB to Amazon S3 buckets (triggers are not implemented in the pattern, need to be added as required) and use that for analytics or long term storage. The scenarios where this pattern can be used are when there are large amounts of data on Amazon DynamoDB and you want to move them to a data lake as part of data strategy, or if the data has to be moved to long term storage due to regulatory reasons. The AWS Glue job copies the data into an encrypted Amazon S3 bucket and stores them in the specified format. In this pattern the format has been set to Parquet.",
11+
"This pattern also creates the required roles and policies for the services, with the right level of permissions required. The roles and policies can be expanded if additional services come into play, based on principle of least privilege."
12+
]
13+
},
14+
"gitHub": {
15+
"template": {
16+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/dynamodb-glue-s3-terraform",
17+
"templateURL": "serverless-patterns/dynamodb-glue-s3-terraform",
18+
"projectFolder": "dynamodb-glue-s3-terraform",
19+
"templateFile": "main.tf"
20+
}
21+
},
22+
"resources": {
23+
"bullets": [
24+
{
25+
"text": "AWS Glue",
26+
"link": "https://docs.aws.amazon.com/glue/latest/dg/what-is-glue.html"
27+
},
28+
{
29+
"text": "Amazon DynamoDB",
30+
"link": "https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html"
31+
},
32+
{
33+
"text": "Amazon S3",
34+
"link": "https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html"
35+
}
36+
]
37+
},
38+
"deploy": {
39+
"text": [
40+
"terraform init",
41+
"terraform plan",
42+
"terraform apply"
43+
]
44+
},
45+
"testing": {
46+
"text": [
47+
"See the GitHub repo for testing instructions."
48+
]
49+
},
50+
"cleanup": {
51+
"text": [
52+
"terraform destroy"
53+
]
54+
},
55+
"authors": [
56+
{
57+
"name": "Kiran Ramamurthy",
58+
"image": "",
59+
"bio": "I am a Senior Partner Solutions Architect for Enterprise Transformation. I work predominantly with partners and specialize in migrations and modernization.",
60+
"linkedin": "kiran-ramamurthy-a96341b",
61+
"twitter": ""
62+
}
63+
],
64+
"patternArch": {
65+
"icon1": {
66+
"x": 20,
67+
"y": 50,
68+
"service": "dynamodb",
69+
"label": "Amazon DynamoDB"
70+
},
71+
"icon2": {
72+
"x": 50,
73+
"y": 50,
74+
"service": "glue",
75+
"label": "AWS Glue"
76+
},
77+
"icon3": {
78+
"x": 80,
79+
"y": 50,
80+
"service": "s3",
81+
"label": "Amazon S3"
82+
},
83+
"line1": {
84+
"from": "icon1",
85+
"to": "icon2",
86+
"label": ""
87+
},
88+
"line2": {
89+
"from": "icon2",
90+
"to": "icon3",
91+
"label": ""
92+
}
93+
}
94+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"title": "Amazon DynamoDB and Amazon S3 zero-ETL integration using AWS Glue",
3+
"description": "Create a Amazon DynamoDB and S3 bucket and integrate them using an AWS Glue job for zero-ETL data transfer.",
4+
"language": "Python",
5+
"level": "200",
6+
"framework": "Terraform",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"This pattern sets up Amazon DynamoDB and Amazon S3 buckets, and integrates them with an AWS Glue job. Using this setup, you can move data from Amazon DynamoDB to Amazon S3 buckets (triggers are not implemented in the pattern, need to be added as required) and use that for analytics or long term storage. The scenarios where this pattern can be used are when there are large amounts of data on Amazon DynamoDB and you want to move them to a data lake as part of data strategy, or if the data has to be moved to long term storage due to regulatory reasons. The AWS Glue job copies the data into an encrypted Amazon S3 bucket and stores them in the specified format. In this pattern the format has been set to Parquet.",
11+
"This pattern also creates the required roles and policies for the services, with the right level of permissions required. The roles and policies can be expanded if additional services come into play, based on principle of least privilege."
12+
]
13+
},
14+
"gitHub": {
15+
"template": {
16+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/dynamodb-glue-s3-terraform",
17+
"templateURL": "serverless-patterns/dynamodb-glue-s3-terraform",
18+
"projectFolder": "dynamodb-glue-s3-terraform",
19+
"templateFile": "main.tf"
20+
}
21+
},
22+
"resources": {
23+
"bullets": [
24+
{
25+
"text": "AWS Glue",
26+
"link": "https://docs.aws.amazon.com/glue/latest/dg/what-is-glue.html"
27+
},
28+
{
29+
"text": "Amazon DynamoDB",
30+
"link": "https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html"
31+
},
32+
{
33+
"text": "Amazon S3",
34+
"link": "https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html"
35+
}
36+
]
37+
},
38+
"deploy": {
39+
"text": [
40+
"terraform init",
41+
"terraform plan",
42+
"terraform apply"
43+
]
44+
},
45+
"testing": {
46+
"text": [
47+
"See the GitHub repo for testing instructions."
48+
]
49+
},
50+
"cleanup": {
51+
"text": [
52+
"terraform destroy"
53+
]
54+
},
55+
"authors": [
56+
{
57+
"name": "Kiran Ramamurthy",
58+
"image": "",
59+
"bio": "I am a Senior Partner Solutions Architect for Enterprise Transformation. I work predominantly with partners and specialize in migrations and modernization.",
60+
"linkedin": "kiran-ramamurthy-a96341b",
61+
"twitter": ""
62+
}
63+
]
64+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#############################################
2+
# This script will be used by Glue for zero
3+
# ETL copy of data from DynamoDB to S3.
4+
#############################################
5+
6+
import sys
7+
from awsglue.transforms import *
8+
from awsglue.utils import getResolvedOptions
9+
from pyspark.context import SparkContext
10+
from awsglue.context import GlueContext
11+
from awsglue.job import Job
12+
13+
args = getResolvedOptions(sys.argv, ['JOB_NAME', 'source_table', 'target_bucket'])
14+
15+
sc = SparkContext()
16+
glueContext = GlueContext(sc)
17+
spark = glueContext.spark_session
18+
job = Job(glueContext)
19+
job.init(args['JOB_NAME'], args)
20+
21+
# Read data from DynamoDB
22+
datasource = glueContext.create_dynamic_frame.from_options(
23+
connection_type="dynamodb",
24+
connection_options={
25+
"dynamodb.input.tableName": args['source_table'],
26+
"dynamodb.throughput.read.percent": "0.5"
27+
}
28+
)
29+
30+
# Write data to S3 in the specified format
31+
glueContext.write_dynamic_frame.from_options(
32+
frame=datasource,
33+
connection_type="s3",
34+
connection_options={
35+
"path": f"s3://{args['target_bucket']}/data/"
36+
},
37+
format="parquet"
38+
)
39+
40+
job.commit()

0 commit comments

Comments
 (0)