internal CdkPipelineStack(Construct scope, string id, CdkPipelineStackProps props = null) : base(scope, id, props) { var sourceArtifact = new Artifact_("SourceArtifact"); var outputArtifact = new Artifact_("OutputArtifact"); var sourceAction = new CodeCommitSourceAction(new CodeCommitSourceActionProps { ActionName = "CodeCommit", Output = sourceArtifact, Repository = props.MyRepository, Branch = "main", }); // Self mutation var pipeline = new CdkPipeline(this, "CdkPipeline", new CdkPipelineProps { PipelineName = "CrossAccountSourcePipeline", CloudAssemblyArtifact = outputArtifact, SourceAction = sourceAction, // It synthesizes CDK code to cdk.out directory which is picked by SelfMutate stage to mutate the pipeline SynthAction = new SimpleSynthAction(new SimpleSynthActionProps { SourceArtifact = sourceArtifact, CloudAssemblyArtifact = outputArtifact, InstallCommands = new[] { "npm install -g aws-cdk", }, BuildCommands = new[] { "dotnet build" }, SynthCommand = "cdk synth", }), }); }
public ElasticbeanstalkBgPipelineStack(Construct scope, string id, IStackProps props = null) : base(scope, id) { var blueEnv = this.Node.TryGetContext("blue_env"); var greenEnv = this.Node.TryGetContext("green_env"); var appName = this.Node.TryGetContext("app_name"); var bucket = new Bucket(this, "BlueGreenBucket", new BucketProps { // The default removal policy is RETAIN, which means that cdk destroy will not attempt to delete // the new bucket, and it will remain in your account until manually deleted. By setting the policy to // DESTROY, cdk destroy will attempt to delete the bucket, but will error if the bucket is not empty. RemovalPolicy = RemovalPolicy.DESTROY // NOT recommended for production code }); var handler = new Function(this, "BlueGreenLambda", new FunctionProps { Runtime = Runtime.PYTHON_3_7, Code = Code.FromAsset("resources"), Handler = "blue_green.lambda_handler", Environment = new Dictionary <string, string> { ["BUCKET"] = bucket.BucketName } }); bucket.GrantReadWrite(handler); var repo = new Repository(this, "Repository", new RepositoryProps { RepositoryName = "MyRepositoryName" }); var pipeline = new Pipeline(this, "MyFirstPipeline"); var sourceStage = pipeline.AddStage(new StageOptions { StageName = "Source" }); var sourceArtifact = new Artifact_("Source"); var sourceAction = new CodeCommitSourceAction(new CodeCommitSourceActionProps { ActionName = "CodeCommit", Repository = repo, Output = sourceArtifact }); sourceStage.AddAction(sourceAction); var deployStage = pipeline.AddStage(new StageOptions { StageName = "Deploy" }); var lambdaAction = new LambdaInvokeAction(new LambdaInvokeActionProps { ActionName = "InvokeAction", Lambda = handler, UserParameters = new Dictionary <string, object> { ["blueEnvironment"] = blueEnv, ["greenEnvironment"] = greenEnv, ["application"] = appName }, Inputs = new Artifact_[] { sourceArtifact } }); deployStage.AddAction(lambdaAction); }