11AWSTemplateFormatVersion : ' 2010-09-09'
22Description : DuckLake stack managed by DBT (Paul)
3+ Transform : AWS::Serverless-2016-10-31
34
45Parameters :
56 SubnetIds :
@@ -8,6 +9,9 @@ Parameters:
89 VpcId :
910 Type : AWS::EC2::VPC::Id
1011 Description : VPC ID for the Database
12+ ImageTag :
13+ Type : String
14+ Description : The tag of the Docker image to use for the DBT container
1115
1216Resources :
1317 LakeBucket :
@@ -54,6 +58,114 @@ Resources:
5458 CapacityProviders :
5559 - FARGATE
5660
61+ LogGroup :
62+ Type : AWS::Logs::LogGroup
63+ Properties :
64+ RetentionInDays : 30
65+
66+ ECSTaskExecutionRole :
67+ Type : AWS::IAM::Role
68+ Properties :
69+ AssumeRolePolicyDocument :
70+ Statement :
71+ - Effect : Allow
72+ Principal :
73+ Service : [ecs-tasks.amazonaws.com]
74+ Action : ['sts:AssumeRole']
75+ Condition :
76+ ArnLike :
77+ aws:SourceArn : !Sub arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:*
78+ StringEquals :
79+ aws:SourceAccount : !Ref AWS::AccountId
80+ Path : /
81+ ManagedPolicyArns :
82+ - arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
83+ Policies :
84+ - PolicyName : LakeBucketFullAccess
85+ PolicyDocument :
86+ Version : " 2012-10-17"
87+ Statement :
88+ - Effect : Allow
89+ Action :
90+ - s3:PutObject
91+ - s3:GetObject
92+ - s3:DeleteObject
93+ - s3:ListBucket
94+ - s3:GetBucketLocation
95+ - s3:PutObjectAcl
96+ - s3:GetObjectAcl
97+ Resource :
98+ - !Sub " ${LakeBucket.Arn}"
99+ - !Sub " ${LakeBucket.Arn}/*"
100+ - Effect : Allow
101+ Action :
102+ - secretsmanager:GetSecretValue
103+ Resource : !GetAtt PostgresDB.MasterUserSecret.SecretArn
104+
105+
106+ DataTransformTaskDefinition :
107+ Type : AWS::ECS::TaskDefinition
108+ Properties :
109+ Family : DataTransform
110+ Cpu : 1024
111+ Memory : 8192
112+ NetworkMode : awsvpc
113+ RequiresCompatibilities :
114+ - FARGATE
115+ ExecutionRoleArn : !GetAtt ECSTaskExecutionRole.Arn
116+ TaskRoleArn : !GetAtt ECSTaskExecutionRole.Arn
117+ RuntimePlatform :
118+ CpuArchitecture : X86_64
119+ ContainerDefinitions :
120+ - Name : dbt
121+ Cpu : 1024
122+ Memory : 8192
123+ Image : !Sub "ghcr.io/sourceallies/duck-lake-example:${ImageTag}"
124+ LogConfiguration :
125+ LogDriver : awslogs
126+ Options :
127+ awslogs-group : !Ref LogGroup
128+ awslogs-region : !Ref AWS::Region
129+ awslogs-stream-prefix : dbt
130+ Command : [run]
131+ Environment :
132+ - Name : PGHOST
133+ Value : !GetAtt PostgresDB.Endpoint.Address
134+ - Name : PGPORT
135+ Value : !GetAtt PostgresDB.Endpoint.Port
136+ - Name : DATA_S3_PATH
137+ Value : !Sub "s3://${LakeBucket}/data/"
138+ Secrets :
139+ - Name : PGUSER
140+ ValueFrom : !Sub "${PostgresDB.MasterUserSecret.SecretArn}:username::"
141+ - Name : PGPASSWORD
142+ ValueFrom : !Sub "${PostgresDB.MasterUserSecret.SecretArn}:password::"
143+
144+ DataTransformStateMachine :
145+ Type : AWS::Serverless::StateMachine
146+ Properties :
147+ Definition :
148+ StartAt : RunDataTransformTask
149+ States :
150+ RunDataTransformTask :
151+ Type : Task
152+ Resource : arn:aws:states:::ecs:runTask.sync
153+ Parameters :
154+ Cluster : !Ref Cluster
155+ TaskDefinition : !Ref DataTransformTaskDefinition
156+ LaunchType : FARGATE
157+ NetworkConfiguration :
158+ AwsvpcConfiguration :
159+ Subnets :
160+ - !Select [ 0, !Ref SubnetIds ]
161+ - !Select [ 1, !Ref SubnetIds ]
162+ AssignPublicIp : ENABLED
163+ SecurityGroups :
164+ - !GetAtt PublicDBSecurityGroup.GroupId
165+ End : true
166+ Policies :
167+ - AmazonECS_FullAccess
168+
57169Outputs :
58170 DBEndpoint :
59171 Description : The connection endpoint for the PostgreSQL instance
0 commit comments