public static FargateTaskDefinition CreateTaskDefinition1(Construct scope)
        {
            var repo = CreateDockerContainerImage(scope);

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

            taskDefinition.AddContainer(Config.ECR_REPO_NAME, new ContainerDefinitionProps()
            {
                MemoryLimitMiB = 2048,
                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[] { "s3:*" });
            taskDefinition.AddToTaskRolePolicy(policyStatement);


            return(taskDefinition);
        }
Esempio n. 2
0
        internal LoadTesterStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            // The code that defines your stack goes here

            var fn = new Function(this, "loadtester", new FunctionProps
            {
                FunctionName = "loadtester",
                Runtime      = Runtime.NODEJS_12_X,
                Code         = Code.FromAsset("src/EdgyRegions/resources/loadtest"),
                Handler      = "index.handler",
                Timeout      = Duration.Minutes(15)
            });
            var poly = new Amazon.CDK.AWS.IAM.PolicyStatement
            {
                Effect = Amazon.CDK.AWS.IAM.Effect.ALLOW,
            };

            poly.AddActions(new string[] { "cloudwatch:PutMetricData" });
            poly.AddAllResources();
            fn.AddToRolePolicy(poly);
        }
Esempio n. 3
0
        internal ColdStartSimulatorStack(Construct scope, string id, StackProps props = null) : base(scope, id, props)
        {
            var coldStartSimulatorLambdaPolicy = new Amazon.CDK.AWS.IAM.PolicyStatement
            {
                Effect = Amazon.CDK.AWS.IAM.Effect.ALLOW
            };

            coldStartSimulatorLambdaPolicy.AddResources("*");
            coldStartSimulatorLambdaPolicy.AddActions("lambda:*");
            coldStartSimulatorLambdaPolicy.AddActions("xray:*");

            var coldStartSimulatorSetupFunction = new Function(this, "coldstartsimulator-setup", new FunctionProps
            {
                FunctionName = "coldstartsimulator-setup",
                Runtime      = Runtime.DOTNET_CORE_3_1,
                Code         = Code.FromAsset("../lambdas/coldstartsimulator/bin/Release/netcoreapp3.1/publish"),
                Handler      = "ColdStartSimulator::ColdStartSimulator.StepFunctionTasks::Setup",
                Timeout      = Duration.Seconds(31),
                MemorySize   = 512
            });

            var coldStartSimulatorInvokeLambdaFunction = new Function(this, "coldstartsimulator-invokelambda", new FunctionProps
            {
                FunctionName = "coldstartsimulator-invokelambda",
                Runtime      = Runtime.DOTNET_CORE_3_1,
                Code         = Code.FromAsset("../lambdas/coldstartsimulator/bin/Release/netcoreapp3.1/publish"),
                Handler      = "ColdStartSimulator::ColdStartSimulator.StepFunctionTasks::InvokeLambda",
                Timeout      = Duration.Seconds(31),
                MemorySize   = 512
            });

            coldStartSimulatorInvokeLambdaFunction.AddToRolePolicy(coldStartSimulatorLambdaPolicy);

            var coldStartSimulatorTouchLambdaFunction = new Function(this, "coldstartsimulator-touchlambda", new FunctionProps
            {
                FunctionName = "coldstartsimulator-touchlambda",
                Runtime      = Runtime.DOTNET_CORE_3_1,
                Code         = Code.FromAsset("../lambdas/coldstartsimulator/bin/Release/netcoreapp3.1/publish"),
                Handler      = "ColdStartSimulator::ColdStartSimulator.StepFunctionTasks::TouchLambda",
                Timeout      = Duration.Seconds(31),
                MemorySize   = 512
            });

            coldStartSimulatorTouchLambdaFunction.AddToRolePolicy(coldStartSimulatorLambdaPolicy);

            var metricS3Bucket = new Bucket(this, "metric-bucket", new BucketProps
            {
                BucketName = "coldstart-metric-bucket",
            });

            var coldStartSimulatorCollectMetricsFunction = new Function(this, "coldstartsimulator-collectmetrics", new FunctionProps
            {
                FunctionName = "coldstartsimulator-collectmetrics",
                Runtime      = Runtime.DOTNET_CORE_3_1,
                Code         = Code.FromAsset("../lambdas/coldstartsimulator/bin/Release/netcoreapp3.1/publish"),
                Handler      = "ColdStartSimulator::ColdStartSimulator.StepFunctionTasks::CollectMetrics",
                Timeout      = Duration.Seconds(31),
                MemorySize   = 512
            });

            metricS3Bucket.GrantPut(coldStartSimulatorCollectMetricsFunction);
            coldStartSimulatorCollectMetricsFunction.AddEnvironment("MetricS3BucketName", metricS3Bucket.BucketName);
            coldStartSimulatorCollectMetricsFunction.AddToRolePolicy(coldStartSimulatorLambdaPolicy);

            var setup = new LambdaInvoke(this, "Setup", new LambdaInvokeProps
            {
                LambdaFunction = coldStartSimulatorSetupFunction,
                OutputPath     = "$.Payload"
            });

            var touch = new LambdaInvoke(this, "Touch", new LambdaInvokeProps
            {
                LambdaFunction = coldStartSimulatorTouchLambdaFunction,
                OutputPath     = "$.Payload"
            });

            var invoke = new LambdaInvoke(this, "Invoke", new LambdaInvokeProps
            {
                LambdaFunction = coldStartSimulatorInvokeLambdaFunction,
                OutputPath     = "$.Payload"
            });

            var collectMetrics = new LambdaInvoke(this, "Collect Metrics", new LambdaInvokeProps
            {
                LambdaFunction = coldStartSimulatorCollectMetricsFunction,
                OutputPath     = "$.Payload"
            });

            var wait3Seconds = new Wait(this, "Wait 3 seconds", new WaitProps
            {
                Time = WaitTime.Duration(Duration.Seconds(3))
            });

            var wait30Seconds = new Wait(this, "Wait 30 seconds", new WaitProps
            {
                Time = WaitTime.Duration(Duration.Seconds(30))
            });

            var invokeAgainChoice = new Choice(this, "Invoke again?");

            invokeAgainChoice.When(Condition.BooleanEquals("$.Continue", true), touch);
            invokeAgainChoice.Otherwise(wait30Seconds);

            wait30Seconds
            .Next(collectMetrics);

            var definition = setup
                             .Next(touch)
                             .Next(wait3Seconds)
                             .Next(invoke)
                             .Next(invokeAgainChoice);

            new StateMachine(this, "ColdStartSimulatorStateMachine", new StateMachineProps
            {
                Definition = definition,
                Timeout    = Duration.Minutes(10)
            });
        }
        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()
            }));
        }