@Generated(value="jsii-pacmak/1.74.0 (build 6d08790)", date="2023-03-14T16:25:29.720Z") public class CfnParametersCode extends Code
Useful when you don't have access to the code of your Lambda from your CDK code, so you can't use Assets, and you want to deploy the Lambda in a CodePipeline, using CloudFormation Actions - you can fill the parameters using the {@link #assign} method.
Example:
Stack lambdaStack = new Stack(app, "LambdaStack"); CfnParametersCode lambdaCode = Code.fromCfnParameters(); Function.Builder.create(lambdaStack, "Lambda") .code(lambdaCode) .handler("index.handler") .runtime(Runtime.NODEJS_14_X) .build(); // other resources that your Lambda needs, added to the lambdaStack... Stack pipelineStack = new Stack(app, "PipelineStack"); Pipeline pipeline = new Pipeline(pipelineStack, "Pipeline"); // add the source code repository containing this code to your Pipeline, // and the source code of the Lambda Function, if they're separate Artifact cdkSourceOutput = new Artifact(); CodeCommitSourceAction cdkSourceAction = CodeCommitSourceAction.Builder.create() .repository(Repository.Builder.create(pipelineStack, "CdkCodeRepo") .repositoryName("CdkCodeRepo") .build()) .actionName("CdkCode_Source") .output(cdkSourceOutput) .build(); Artifact lambdaSourceOutput = new Artifact(); CodeCommitSourceAction lambdaSourceAction = CodeCommitSourceAction.Builder.create() .repository(Repository.Builder.create(pipelineStack, "LambdaCodeRepo") .repositoryName("LambdaCodeRepo") .build()) .actionName("LambdaCode_Source") .output(lambdaSourceOutput) .build(); pipeline.addStage(StageOptions.builder() .stageName("Source") .actions(List.of(cdkSourceAction, lambdaSourceAction)) .build()); // synthesize the Lambda CDK template, using CodeBuild // the below values are just examples, assuming your CDK code is in TypeScript/JavaScript - // adjust the build environment and/or commands accordingly Project cdkBuildProject = Project.Builder.create(pipelineStack, "CdkBuildProject") .environment(BuildEnvironment.builder() .buildImage(LinuxBuildImage.UBUNTU_14_04_NODEJS_10_1_0) .build()) .buildSpec(BuildSpec.fromObject(Map.of( "version", "0.2", "phases", Map.of( "install", Map.of( "commands", "npm install"), "build", Map.of( "commands", List.of("npm run build", "npm run cdk synth LambdaStack -- -o ."))), "artifacts", Map.of( "files", "LambdaStack.template.yaml")))) .build(); Artifact cdkBuildOutput = new Artifact(); CodeBuildAction cdkBuildAction = CodeBuildAction.Builder.create() .actionName("CDK_Build") .project(cdkBuildProject) .input(cdkSourceOutput) .outputs(List.of(cdkBuildOutput)) .build(); // build your Lambda code, using CodeBuild // again, this example assumes your Lambda is written in TypeScript/JavaScript - // make sure to adjust the build environment and/or commands if they don't match your specific situation Project lambdaBuildProject = Project.Builder.create(pipelineStack, "LambdaBuildProject") .environment(BuildEnvironment.builder() .buildImage(LinuxBuildImage.UBUNTU_14_04_NODEJS_10_1_0) .build()) .buildSpec(BuildSpec.fromObject(Map.of( "version", "0.2", "phases", Map.of( "install", Map.of( "commands", "npm install"), "build", Map.of( "commands", "npm run build")), "artifacts", Map.of( "files", List.of("index.js", "node_modules/**/*"))))) .build(); Artifact lambdaBuildOutput = new Artifact(); CodeBuildAction lambdaBuildAction = CodeBuildAction.Builder.create() .actionName("Lambda_Build") .project(lambdaBuildProject) .input(lambdaSourceOutput) .outputs(List.of(lambdaBuildOutput)) .build(); pipeline.addStage(StageOptions.builder() .stageName("Build") .actions(List.of(cdkBuildAction, lambdaBuildAction)) .build()); // finally, deploy your Lambda Stack pipeline.addStage(StageOptions.builder() .stageName("Deploy") .actions(List.of( CloudFormationCreateUpdateStackAction.Builder.create() .actionName("Lambda_CFN_Deploy") .templatePath(cdkBuildOutput.atPath("LambdaStack.template.yaml")) .stackName("LambdaStackDeployedName") .adminPermissions(true) .parameterOverrides(lambdaCode.assign(lambdaBuildOutput.getS3Location())) .extraInputs(List.of(lambdaBuildOutput)) .build())) .build());
Modifier and Type | Class and Description |
---|---|
static class |
CfnParametersCode.Builder
A fluent builder for
CfnParametersCode . |
Modifier | Constructor and Description |
---|---|
|
CfnParametersCode() |
protected |
CfnParametersCode(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) |
protected |
CfnParametersCode(software.amazon.jsii.JsiiObjectRef objRef) |
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
assign(Location location)
Create a parameters map from this instance's CloudFormation parameters.
|
CodeConfig |
bind(Construct scope)
Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
|
java.lang.String |
getBucketNameParam() |
java.lang.Boolean |
getIsInline()
Determines whether this Code is inline code or not.
|
java.lang.String |
getObjectKeyParam() |
asset, bindToResource, bindToResource, bucket, bucket, cfnParameters, cfnParameters, fromAsset, fromAsset, fromAssetImage, fromAssetImage, fromBucket, fromBucket, fromCfnParameters, fromCfnParameters, fromDockerBuild, fromDockerBuild, fromEcrImage, fromEcrImage, fromInline, inline
protected CfnParametersCode(software.amazon.jsii.JsiiObjectRef objRef)
protected CfnParametersCode(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
public CfnParametersCode()
public java.util.Map<java.lang.String,java.lang.Object> assign(Location location)
It returns a map with 2 keys that correspond to the names of the parameters defined in this Lambda code,
and as values it contains the appropriate expressions pointing at the provided S3 location
(most likely, obtained from a CodePipeline Artifact by calling the artifact.s3Location
method).
The result should be provided to the CloudFormation Action
that is deploying the Stack that the Lambda with this code is part of,
in the parameterOverrides
property.
location
- the location of the object in S3 that represents the Lambda code. This parameter is required.public CodeConfig bind(Construct scope)
public java.lang.String getBucketNameParam()
public java.lang.Boolean getIsInline()
getIsInline
in class Code
public java.lang.String getObjectKeyParam()