Exemple #1
0
        internal PollyStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            // Lambda Function that takes in text and returns a polly voice synthesis
            _pollyFunction = new Lambda.Function(this, "pollyHandler", new Lambda.FunctionProps
            {
                Runtime = Lambda.Runtime.PYTHON_3_8,
                Code    = Lambda.Code.FromAsset("lambda_fns"),
                Handler = "polly.handler"
            });

            // https://docs.aws.amazon.com/polly/latest/dg/api-permissions-reference.html
            // https://docs.aws.amazon.com/translate/latest/dg/translate-api-permissions-ref.html
            _pollyPolicy = new IAM.PolicyStatement(new IAM.PolicyStatementProps
            {
                Effect    = IAM.Effect.ALLOW,
                Resources = new[] { "*" },
                Actions   = new[]
                {
                    "translate:TranslateText", "polly:SynthesizeSpeech"
                }
            });

            _pollyFunction.AddToRolePolicy(_pollyPolicy);

            // defines an API Gateway Http API resource backed by our "pollyHandler" function.
            _httpApi = new APIGatewayV2.HttpApi(this, "Polly", new APIGatewayV2.HttpApiProps
            {
                DefaultIntegration = new APIGatewayV2Integrations.LambdaProxyIntegration(
                    new APIGatewayV2Integrations.LambdaProxyIntegrationProps
                {
                    Handler = _pollyFunction
                })
            });

            new CfnOutput(this, "HTTP API Url", new CfnOutputProps
            {
                Value = _httpApi.Url
            });
        }
        internal DotnetPipelineStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            string REPO_NAME  = "dotnet-pipeline";
            string STACK_NAME = "DotnetFunctionalStack";

            var code = Repository.FromRepositoryName(this, "ImportedRepo", REPO_NAME);

            var sourceOutput = new Artifact_();

            var cdkDeploy = new PipelineProject(this, "CDKDeploy", new PipelineProjectProps
            {
                BuildSpec = BuildSpec.FromObject(new Dictionary <string, object> {
                    ["version"] = "0.2",
                    ["phases"]  = new Dictionary <string, object>
                    {
                        ["install"] = new Dictionary <string, string>
                        {
                            ["commands"] = "npm install -g aws-cdk"
                        },
                        ["build"] = new Dictionary <string, object>
                        {
                            ["commands"] = new [] { "src/scripts/build.sh", "cdk deploy " + STACK_NAME }
                        }
                    }
                }),
                Environment = new BuildEnvironment {
                    BuildImage = LinuxBuildImage.AMAZON_LINUX_2_3
                }
            });

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

            statement.Effect = Effect.ALLOW;
            statement.AddActions(new [] { "*" });
            statement.AddAllResources();
            cdkDeploy.Role.AddToPolicy(statement);

            var pipeline = new Amazon.CDK.AWS.CodePipeline.Pipeline(this, "Pipeline", new PipelineProps {
                Stages = new [] {
                    new StageProps
                    {
                        StageName = "Source",
                        Actions   = new []
                        {
                            new CodeCommitSourceAction(new CodeCommitSourceActionProps
                            {
                                ActionName = "Source",
                                Repository = code,
                                Output     = sourceOutput
                            })
                        }
                    },
                    new StageProps
                    {
                        StageName = "Deploy",
                        Actions   = new []
                        {
                            new CodeBuildAction(new CodeBuildActionProps
                            {
                                ActionName = "CDK_Deploy",
                                Project    = cdkDeploy,
                                Input      = sourceOutput
                            })
                        }
                    }
                }
            });
        }