|
| 1 | +Description: Cloudformation Stack for Deploying Metaflowbot |
| 2 | +Parameters: |
| 3 | + AdminEmailAddress: |
| 4 | + Description: Email address of the admin user in the slack workspace |
| 5 | + Type: String |
| 6 | + MetadataServiceAuthParameterKey: |
| 7 | + Default: METADATASERVICE_AUTH_KEY |
| 8 | + Description: Key for Metadata service auth parameter in Secrets Manager. |
| 9 | + Type: String |
| 10 | + MetadataServiceUrl: |
| 11 | + Description: URL of the metadata service |
| 12 | + Type: String |
| 13 | + MetaflowDatastoreSysrootS3: |
| 14 | + Description: 'Amazon S3 URL for Metaflow DataStore ' |
| 15 | + Type: String |
| 16 | + MetaflowbotSecretsManagerARN: |
| 17 | + Description: ARN of the secret holding Metaflowbot credentials in Secrets Manager |
| 18 | + Type: String |
| 19 | + SlackAppTokenParameterKey: |
| 20 | + Default: SLACK_APP_TOKEN_KEY |
| 21 | + Description: Key for SLACK_APP_TOKEN parameter in Secrets Manager. |
| 22 | + Type: String |
| 23 | + SlackBotTokenParameterKey: |
| 24 | + Default: SLACK_BOT_TOKEN_KEY |
| 25 | + Description: Key for SLACK_BOT_TOKEN parameter in Secrets Manager. |
| 26 | + Type: String |
| 27 | +Resources: |
| 28 | + EcsClusterRole: |
| 29 | + Properties: |
| 30 | + AssumeRolePolicyDocument: |
| 31 | + Statement: |
| 32 | + - Action: sts:AssumeRole |
| 33 | + Effect: Allow |
| 34 | + Principal: |
| 35 | + Service: ecs-tasks.amazonaws.com |
| 36 | + Version: '2012-10-17' |
| 37 | + ManagedPolicyArns: |
| 38 | + - arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM |
| 39 | + Path: / |
| 40 | + Type: AWS::IAM::Role |
| 41 | + EcsTaskRole: |
| 42 | + Properties: |
| 43 | + AssumeRolePolicyDocument: |
| 44 | + Statement: |
| 45 | + - Action: sts:AssumeRole |
| 46 | + Effect: Allow |
| 47 | + Principal: |
| 48 | + Service: ecs-tasks.amazonaws.com |
| 49 | + Version: '2012-10-17' |
| 50 | + Path: / |
| 51 | + Type: AWS::IAM::Role |
| 52 | + InternetGatewayAttachment: |
| 53 | + Properties: |
| 54 | + InternetGatewayId: !Ref 'MetaflowbotInternetGateway' |
| 55 | + VpcId: !Ref 'MetaflowbotPublicVpc' |
| 56 | + Type: AWS::EC2::VPCGatewayAttachment |
| 57 | + MetaflowbotCluster: |
| 58 | + Type: AWS::ECS::Cluster |
| 59 | + MetaflowbotDeployment: |
| 60 | + Properties: |
| 61 | + Cluster: !Ref 'MetaflowbotCluster' |
| 62 | + DesiredCount: 1 |
| 63 | + LaunchType: FARGATE |
| 64 | + NetworkConfiguration: |
| 65 | + AwsvpcConfiguration: |
| 66 | + AssignPublicIp: ENABLED |
| 67 | + SecurityGroups: |
| 68 | + - !Ref 'MetaflowbotSecurityGroup' |
| 69 | + Subnets: |
| 70 | + - !Ref 'MetaflowbotDeploymentSubnet' |
| 71 | + TaskDefinition: !Ref 'MetaflowbotTaskDefinition' |
| 72 | + Type: AWS::ECS::Service |
| 73 | + MetaflowbotDeploymentSubnet: |
| 74 | + Properties: |
| 75 | + AvailabilityZone: !Select |
| 76 | + - 0 |
| 77 | + - !GetAZs |
| 78 | + Ref: AWS::Region |
| 79 | + CidrBlock: 10.0.0.0/24 |
| 80 | + MapPublicIpOnLaunch: true |
| 81 | + VpcId: !Ref 'MetaflowbotPublicVpc' |
| 82 | + Type: AWS::EC2::Subnet |
| 83 | + MetaflowbotInternetGateway: |
| 84 | + Type: AWS::EC2::InternetGateway |
| 85 | + MetaflowbotLogGroup: |
| 86 | + Properties: |
| 87 | + LogGroupName: !Join |
| 88 | + - '' |
| 89 | + - - /ecs/ |
| 90 | + - !Ref 'AWS::StackName' |
| 91 | + - -metaflowbot |
| 92 | + Type: AWS::Logs::LogGroup |
| 93 | + MetaflowbotPublicVpc: |
| 94 | + Properties: |
| 95 | + CidrBlock: 10.0.0.0/16 |
| 96 | + Type: AWS::EC2::VPC |
| 97 | + MetaflowbotSecretAccess: |
| 98 | + Properties: |
| 99 | + PolicyDocument: |
| 100 | + Statement: |
| 101 | + - Action: |
| 102 | + - secretsmanager:GetSecretValue |
| 103 | + Effect: Allow |
| 104 | + Resource: |
| 105 | + - !Ref 'MetaflowbotSecretsManagerARN' |
| 106 | + Sid: S3GetObject |
| 107 | + Version: '2012-10-17' |
| 108 | + PolicyName: Metaflowbot |
| 109 | + Roles: |
| 110 | + - !Ref 'EcsClusterRole' |
| 111 | + Type: AWS::IAM::Policy |
| 112 | + MetaflowbotSecurityGroup: |
| 113 | + Properties: |
| 114 | + GroupDescription: Allow All In and outbound traffic |
| 115 | + SecurityGroupEgress: |
| 116 | + - CidrIp: '0.0.0.0/0' |
| 117 | + FromPort: 0 |
| 118 | + IpProtocol: tcp |
| 119 | + ToPort: 65534 |
| 120 | + VpcId: !Ref 'MetaflowbotPublicVpc' |
| 121 | + Type: AWS::EC2::SecurityGroup |
| 122 | + MetaflowbotTaskDefinition: |
| 123 | + Properties: |
| 124 | + ContainerDefinitions: |
| 125 | + - Environment: |
| 126 | + - Name: ADMIN_USER_ADDRESS |
| 127 | + Value: !Ref 'AdminEmailAddress' |
| 128 | + - Name: USERNAME |
| 129 | + Value: slackbot |
| 130 | + - Name: METAFLOW_SERVICE_URL |
| 131 | + Value: !Ref 'MetadataServiceUrl' |
| 132 | + - Name: METAFLOW_DATASTORE_SYSROOT_S3 |
| 133 | + Value: !Ref 'MetaflowDatastoreSysrootS3' |
| 134 | + - Name: METAFLOW_DEFAULT_DATASTORE |
| 135 | + Value: s3 |
| 136 | + - Name: METAFLOW_DEFAULT_METADATA |
| 137 | + Value: service |
| 138 | + Essential: true |
| 139 | + Image: outerbounds/metaflowbot |
| 140 | + LogConfiguration: |
| 141 | + LogDriver: awslogs |
| 142 | + Options: |
| 143 | + awslogs-group: !Join |
| 144 | + - '' |
| 145 | + - - /ecs/ |
| 146 | + - !Ref 'AWS::StackName' |
| 147 | + - -metaflowbot |
| 148 | + awslogs-region: !Ref 'AWS::Region' |
| 149 | + awslogs-stream-prefix: ecs |
| 150 | + Name: metaflowbot |
| 151 | + Secrets: |
| 152 | + - Name: METAFLOW_SERVICE_AUTH_KEY |
| 153 | + ValueFrom: !Join |
| 154 | + - '' |
| 155 | + - - !Ref 'MetaflowbotSecretsManagerARN' |
| 156 | + - ':' |
| 157 | + - !Ref 'MetadataServiceAuthParameterKey' |
| 158 | + - '::' |
| 159 | + - Name: SLACK_APP_TOKEN |
| 160 | + ValueFrom: !Join |
| 161 | + - '' |
| 162 | + - - !Ref 'MetaflowbotSecretsManagerARN' |
| 163 | + - ':' |
| 164 | + - !Ref 'SlackAppTokenParameterKey' |
| 165 | + - '::' |
| 166 | + - Name: SLACK_BOT_TOKEN |
| 167 | + ValueFrom: !Join |
| 168 | + - '' |
| 169 | + - - !Ref 'MetaflowbotSecretsManagerARN' |
| 170 | + - ':' |
| 171 | + - !Ref 'SlackBotTokenParameterKey' |
| 172 | + - '::' |
| 173 | + Cpu: '4096' |
| 174 | + ExecutionRoleArn: !GetAtt 'EcsClusterRole.Arn' |
| 175 | + Memory: '8192' |
| 176 | + NetworkMode: awsvpc |
| 177 | + RequiresCompatibilities: |
| 178 | + - FARGATE |
| 179 | + TaskRoleArn: !GetAtt 'EcsTaskRole.Arn' |
| 180 | + Type: AWS::ECS::TaskDefinition |
| 181 | + PolicyEcr: |
| 182 | + Properties: |
| 183 | + PolicyDocument: |
| 184 | + Statement: |
| 185 | + - Action: |
| 186 | + - ecr:GetAuthorizationToken |
| 187 | + Effect: Allow |
| 188 | + Resource: |
| 189 | + - '*' |
| 190 | + - Action: |
| 191 | + - ecr:GetDownloadUrlForLayer |
| 192 | + - ecr:BatchGetImage |
| 193 | + - ecr:BatchCheckLayerAvailability |
| 194 | + - logs:CreateLogStream |
| 195 | + - logs:PutLogEvents |
| 196 | + Effect: Allow |
| 197 | + Resource: |
| 198 | + - '*' |
| 199 | + Sid: AllowPull |
| 200 | + Version: '2012-10-17' |
| 201 | + PolicyName: MetaflowbotEcrPolicy |
| 202 | + Roles: |
| 203 | + - !Ref 'EcsClusterRole' |
| 204 | + Type: AWS::IAM::Policy |
| 205 | + PublicDefaultRoute: |
| 206 | + Properties: |
| 207 | + DestinationCidrBlock: '0.0.0.0/0' |
| 208 | + GatewayId: !Ref 'MetaflowbotInternetGateway' |
| 209 | + RouteTableId: !Ref 'PublicRouteTable' |
| 210 | + Type: AWS::EC2::Route |
| 211 | + PublicRouteAssociation: |
| 212 | + Properties: |
| 213 | + RouteTableId: !Ref 'PublicRouteTable' |
| 214 | + SubnetId: !Ref 'MetaflowbotDeploymentSubnet' |
| 215 | + Type: AWS::EC2::SubnetRouteTableAssociation |
| 216 | + PublicRouteTable: |
| 217 | + Properties: |
| 218 | + VpcId: !Ref 'MetaflowbotPublicVpc' |
| 219 | + Type: AWS::EC2::RouteTable |
| 220 | + S3AccessPolicy: |
| 221 | + Properties: |
| 222 | + PolicyDocument: |
| 223 | + Statement: |
| 224 | + - Action: |
| 225 | + - s3:GetObject |
| 226 | + - s3:ListBucket |
| 227 | + Effect: Allow |
| 228 | + Resource: |
| 229 | + - !Join |
| 230 | + - '' |
| 231 | + - - !Join |
| 232 | + - '' |
| 233 | + - - 'arn:aws:s3:::' |
| 234 | + - !Select |
| 235 | + - 1 |
| 236 | + - !Split |
| 237 | + - s3:// |
| 238 | + - !Ref 'MetaflowDatastoreSysrootS3' |
| 239 | + - /* |
| 240 | + Sid: S3GetObject |
| 241 | + Version: '2012-10-17' |
| 242 | + PolicyName: MetaflowbotS3AccessPolicy |
| 243 | + Roles: |
| 244 | + - !Ref 'EcsTaskRole' |
| 245 | + Type: AWS::IAM::Policy |
| 246 | + |
0 commit comments