Example #1
0
        private string GetStageEcr(Construct scope, string ecrRepositoryName, Configuration configuration)
        {
            if (string.IsNullOrWhiteSpace(configuration.Ecrs.Stage))
            {
                var repository = new Amazon.CDK.AWS.ECR.Repository(scope, "StageEcr", new RepositoryProps
                {
                    RepositoryName = ecrRepositoryName
                });
                return(GetEcr(repository.RepositoryUri));
            }

            return(configuration.Ecrs.Stage);
        }
        public static Amazon.CDK.AWS.ECR.Repository CreateDockerContainerImage(Construct scope)
        {
            var repo = new Amazon.CDK.AWS.ECR.Repository(scope, "ECRRepo", new Amazon.CDK.AWS.ECR.RepositoryProps()
            {
                RemovalPolicy  = RemovalPolicy.DESTROY,
                RepositoryName = Config.ECR_REPO_NAME
            });

            repo.AddToResourcePolicy(new Amazon.CDK.AWS.IAM.PolicyStatement(new Amazon.CDK.AWS.IAM.PolicyStatementProps
            {
                Effect  = Amazon.CDK.AWS.IAM.Effect.ALLOW,
                Actions = new string[] { "ecr:*" }
            }));

            return(repo);
        }
        public static Amazon.CDK.AWS.StepFunctions.Tasks.EcsRunTask CreateTask(Construct scope, Table presortTable)
        {
            var environmentCID = Amazon.CDK.AWS.SSM.StringParameter.ValueFromLookup(scope, Config.PARAMETER_STORE_AWS_ACCOUNTID_CICD);

            var repo = new Amazon.CDK.AWS.ECR.Repository(scope, "ECRRepo", new Amazon.CDK.AWS.ECR.RepositoryProps()
            {
                RemovalPolicy  = RemovalPolicy.DESTROY,
                RepositoryName = Config.ECR_REPO_NAME
            });

            repo.AddToResourcePolicy(new Amazon.CDK.AWS.IAM.PolicyStatement(new Amazon.CDK.AWS.IAM.PolicyStatementProps
            {
                Effect     = Amazon.CDK.AWS.IAM.Effect.ALLOW,
                Actions    = new string[] { "ecr:*" },
                Principals = new Amazon.CDK.AWS.IAM.IPrincipal[]
                {
                    new Amazon.CDK.AWS.IAM.ArnPrincipal("arn:aws:iam::" + environmentCID + ":root")
                }
            }));


            var taskDefinition = new FargateTaskDefinition(scope, "DownloadAccuzipFileTaskDefinition", new FargateTaskDefinitionProps()
            {
                Cpu            = 4096,
                MemoryLimitMiB = 8192,
            });

            var containerDefinition = taskDefinition.AddContainer(Config.ECR_REPO_NAME + "1", new ContainerDefinitionProps()
            {
                Cpu            = 4096,
                MemoryLimitMiB = 8192,
                Image          = ContainerImage.FromEcrRepository(repo),
                Logging        = new AwsLogDriver(new AwsLogDriverProps()
                {
                    StreamPrefix = "dmappresort"
                })
            });


            var policyStatement = new Amazon.CDK.AWS.IAM.PolicyStatement();

            policyStatement.AddAllResources();
            policyStatement.AddActions(new string[] { "dynamoDb:*", "ses:*", "s3:*" });
            taskDefinition.AddToTaskRolePolicy(policyStatement);



            var cluster = CreateCluster(scope);


            var lstEnviron = new List <TaskEnvironmentVariable>();

            //lstEnviron.Add(new TaskEnvironmentVariable
            //{
            //    Name = "accuzipFileS3key",
            //    Value = JsonPath.StringAt("$.accuzipFileS3key")
            //});

            //lstEnviron.Add(new TaskEnvironmentVariable
            //{
            //    Name = "beforeReduceFileS3Key",
            //    Value = JsonPath.StringAt("$.beforeReduceFileS3Key")
            //});


            //lstEnviron.Add(new TaskEnvironmentVariable
            //{
            //    Name = "bucketName",
            //    Value = JsonPath.StringAt("$.bucketName")
            //});

            //lstEnviron.Add(new TaskEnvironmentVariable
            //{
            //    Name = "apiKey",
            //    Value = JsonPath.StringAt("$.apiKey")
            //});

            lstEnviron.Add(new TaskEnvironmentVariable
            {
                Name  = "REQUESTID",
                Value = JsonPath.StringAt("$.requestId")
            });

            lstEnviron.Add(new TaskEnvironmentVariable
            {
                Name  = "DYNAMO_TABLE",
                Value = presortTable.TableName
            });



            return(new EcsRunTask(scope, "FileMergeFargate", new EcsRunTaskProps()
            {
                LaunchTarget = new EcsFargateLaunchTarget(),
                AssignPublicIp = true,
                IntegrationPattern = IntegrationPattern.RUN_JOB,
                Cluster = cluster,
                TaskDefinition = taskDefinition,
                ContainerOverrides = (new List <ContainerOverride>
                {
                    new ContainerOverride
                    {
                        ContainerDefinition = containerDefinition,
                        Environment = lstEnviron.ToArray()
                    }
                }).ToArray()
            }));
        }