CfnParametersCode Class
Lambda code defined using 2 CloudFormation parameters.
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 #assign method.
Example
const lambdaStack = new cdk.Stack(app, 'LambdaStack');
const lambdaCode = lambda.Code.fromCfnParameters();
new lambda.Function(lambdaStack, 'Lambda', {
code: lambdaCode,
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_LATEST,
});
// other resources that your Lambda needs, added to the lambdaStack...
const pipelineStack = new cdk.Stack(app, 'PipelineStack');
const pipeline = new codepipeline.Pipeline(pipelineStack, 'Pipeline', {
crossAccountKeys: true,
});
// add the source code repository containing this code to your Pipeline,
// and the source code of the Lambda Function, if they're separate
const cdkSourceOutput = new codepipeline.Artifact();
const cdkSourceAction = new codepipeline_actions.CodeCommitSourceAction({
repository: new codecommit.Repository(pipelineStack, 'CdkCodeRepo', {
repositoryName: 'CdkCodeRepo',
}),
actionName: 'CdkCode_Source',
output: cdkSourceOutput,
});
const lambdaSourceOutput = new codepipeline.Artifact();
const lambdaSourceAction = new codepipeline_actions.CodeCommitSourceAction({
repository: new codecommit.Repository(pipelineStack, 'LambdaCodeRepo', {
repositoryName: 'LambdaCodeRepo',
}),
actionName: 'LambdaCode_Source',
output: lambdaSourceOutput,
});
pipeline.addStage({
stageName: 'Source',
actions: [cdkSourceAction, lambdaSourceAction],
});
// 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
const cdkBuildProject = new codebuild.Project(pipelineStack, 'CdkBuildProject', {
environment: {
buildImage: codebuild.LinuxBuildImage.STANDARD_7_0,
},
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
install: {
commands: 'npm install',
},
build: {
commands: [
'npm run build',
'npm run cdk synth LambdaStack -- -o .',
],
},
},
artifacts: {
files: 'LambdaStack.template.yaml',
},
}),
});
const cdkBuildOutput = new codepipeline.Artifact();
const cdkBuildAction = new codepipeline_actions.CodeBuildAction({
actionName: 'CDK_Build',
project: cdkBuildProject,
input: cdkSourceOutput,
outputs: [cdkBuildOutput],
});
// 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
const lambdaBuildProject = new codebuild.Project(pipelineStack, 'LambdaBuildProject', {
environment: {
buildImage: codebuild.LinuxBuildImage.STANDARD_7_0,
},
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
install: {
commands: 'npm install',
},
build: {
commands: 'npm run build',
},
},
artifacts: {
files: [
'index.js',
'node_modules/**/*',
],
},
}),
});
const lambdaBuildOutput = new codepipeline.Artifact();
const lambdaBuildAction = new codepipeline_actions.CodeBuildAction({
actionName: 'Lambda_Build',
project: lambdaBuildProject,
input: lambdaSourceOutput,
outputs: [lambdaBuildOutput],
});
pipeline.addStage({
stageName: 'Build',
actions: [cdkBuildAction, lambdaBuildAction],
});
// finally, deploy your Lambda Stack
pipeline.addStage({
stageName: 'Deploy',
actions: [
new codepipeline_actions.CloudFormationCreateUpdateStackAction({
actionName: 'Lambda_CFN_Deploy',
templatePath: cdkBuildOutput.atPath('LambdaStack.template.yaml'),
stackName: 'LambdaStackDeployedName',
adminPermissions: true,
parameterOverrides: lambdaCode.assign(lambdaBuildOutput.s3Location),
extraInputs: [
lambdaBuildOutput,
],
}),
],
});
lambda_stack = cdk.Stack(app, "LambdaStack")
lambda_code = lambda_.Code.from_cfn_parameters()
lambda_.Function(lambda_stack, "Lambda",
code=lambda_code,
handler="index.handler",
runtime=lambda_.Runtime.NODEJS_LATEST
)
# other resources that your Lambda needs, added to the lambdaStack...
pipeline_stack = cdk.Stack(app, "PipelineStack")
pipeline = codepipeline.Pipeline(pipeline_stack, "Pipeline",
cross_account_keys=True
)
# add the source code repository containing this code to your Pipeline,
# and the source code of the Lambda Function, if they're separate
cdk_source_output = codepipeline.Artifact()
cdk_source_action = codepipeline_actions.CodeCommitSourceAction(
repository=codecommit.Repository(pipeline_stack, "CdkCodeRepo",
repository_name="CdkCodeRepo"
),
action_name="CdkCode_Source",
output=cdk_source_output
)
lambda_source_output = codepipeline.Artifact()
lambda_source_action = codepipeline_actions.CodeCommitSourceAction(
repository=codecommit.Repository(pipeline_stack, "LambdaCodeRepo",
repository_name="LambdaCodeRepo"
),
action_name="LambdaCode_Source",
output=lambda_source_output
)
pipeline.add_stage(
stage_name="Source",
actions=[cdk_source_action, lambda_source_action]
)
# 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
cdk_build_project = codebuild.Project(pipeline_stack, "CdkBuildProject",
environment=codebuild.BuildEnvironment(
build_image=codebuild.LinuxBuildImage.STANDARD_7_0
),
build_spec=codebuild.BuildSpec.from_object({
"version": "0.2",
"phases": {
"install": {
"commands": "npm install"
},
"build": {
"commands": ["npm run build", "npm run cdk synth LambdaStack -- -o ."
]
}
},
"artifacts": {
"files": "LambdaStack.template.yaml"
}
})
)
cdk_build_output = codepipeline.Artifact()
cdk_build_action = codepipeline_actions.CodeBuildAction(
action_name="CDK_Build",
project=cdk_build_project,
input=cdk_source_output,
outputs=[cdk_build_output]
)
# 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
lambda_build_project = codebuild.Project(pipeline_stack, "LambdaBuildProject",
environment=codebuild.BuildEnvironment(
build_image=codebuild.LinuxBuildImage.STANDARD_7_0
),
build_spec=codebuild.BuildSpec.from_object({
"version": "0.2",
"phases": {
"install": {
"commands": "npm install"
},
"build": {
"commands": "npm run build"
}
},
"artifacts": {
"files": ["index.js", "node_modules/**/*"
]
}
})
)
lambda_build_output = codepipeline.Artifact()
lambda_build_action = codepipeline_actions.CodeBuildAction(
action_name="Lambda_Build",
project=lambda_build_project,
input=lambda_source_output,
outputs=[lambda_build_output]
)
pipeline.add_stage(
stage_name="Build",
actions=[cdk_build_action, lambda_build_action]
)
# finally, deploy your Lambda Stack
pipeline.add_stage(
stage_name="Deploy",
actions=[
codepipeline_actions.CloudFormationCreateUpdateStackAction(
action_name="Lambda_CFN_Deploy",
template_path=cdk_build_output.at_path("LambdaStack.template.yaml"),
stack_name="LambdaStackDeployedName",
admin_permissions=True,
parameter_overrides=lambda_code.assign(lambda_build_output.s3_location),
extra_inputs=[lambda_build_output
]
)
]
)
Stack lambdaStack = new Stack(app, "LambdaStack");
CfnParametersCode lambdaCode = Code.fromCfnParameters();
Function.Builder.create(lambdaStack, "Lambda")
.code(lambdaCode)
.handler("index.handler")
.runtime(Runtime.NODEJS_LATEST)
.build();
// other resources that your Lambda needs, added to the lambdaStack...
Stack pipelineStack = new Stack(app, "PipelineStack");
Pipeline pipeline = Pipeline.Builder.create(pipelineStack, "Pipeline")
.crossAccountKeys(true)
.build();
// 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.STANDARD_7_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.STANDARD_7_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());
// Install: dotnet add package Amazon.CDK.Lib
var lambdaStack = new Stack(app, "LambdaStack");
var lambdaCode = Code.FromCfnParameters();
new Function(lambdaStack, "Lambda", new FunctionProps {
Code = lambdaCode,
Handler = "index.handler",
Runtime = Runtime.NODEJS_LATEST
});
// other resources that your Lambda needs, added to the lambdaStack...
var pipelineStack = new Stack(app, "PipelineStack");
var pipeline = new Pipeline(pipelineStack, "Pipeline", new PipelineProps {
CrossAccountKeys = true
});
// add the source code repository containing this code to your Pipeline,
// and the source code of the Lambda Function, if they're separate
var cdkSourceOutput = new Artifact();
var cdkSourceAction = new CodeCommitSourceAction(new CodeCommitSourceActionProps {
Repository = new Repository(pipelineStack, "CdkCodeRepo", new RepositoryProps {
RepositoryName = "CdkCodeRepo"
}),
ActionName = "CdkCode_Source",
Output = cdkSourceOutput
});
var lambdaSourceOutput = new Artifact();
var lambdaSourceAction = new CodeCommitSourceAction(new CodeCommitSourceActionProps {
Repository = new Repository(pipelineStack, "LambdaCodeRepo", new RepositoryProps {
RepositoryName = "LambdaCodeRepo"
}),
ActionName = "LambdaCode_Source",
Output = lambdaSourceOutput
});
pipeline.AddStage(new StageOptions {
StageName = "Source",
Actions = new [] { cdkSourceAction, lambdaSourceAction }
});
// 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
var cdkBuildProject = new Project(pipelineStack, "CdkBuildProject", new ProjectProps {
Environment = new BuildEnvironment {
BuildImage = LinuxBuildImage.STANDARD_7_0
},
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" },
{ "phases", new Dictionary<string, IDictionary<string, string>> {
{ "install", new Struct {
Commands = "npm install"
} },
{ "build", new Struct {
Commands = new [] { "npm run build", "npm run cdk synth LambdaStack -- -o ." }
} }
} },
{ "artifacts", new Dictionary<string, string> {
{ "files", "LambdaStack.template.yaml" }
} }
})
});
var cdkBuildOutput = new Artifact();
var cdkBuildAction = new CodeBuildAction(new CodeBuildActionProps {
ActionName = "CDK_Build",
Project = cdkBuildProject,
Input = cdkSourceOutput,
Outputs = new [] { cdkBuildOutput }
});
// 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
var lambdaBuildProject = new Project(pipelineStack, "LambdaBuildProject", new ProjectProps {
Environment = new BuildEnvironment {
BuildImage = LinuxBuildImage.STANDARD_7_0
},
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" },
{ "phases", new Dictionary<string, IDictionary<string, string>> {
{ "install", new Struct {
Commands = "npm install"
} },
{ "build", new Struct {
Commands = "npm run build"
} }
} },
{ "artifacts", new Dictionary<string, string[]> {
{ "files", new [] { "index.js", "node_modules/**/*" } }
} }
})
});
var lambdaBuildOutput = new Artifact();
var lambdaBuildAction = new CodeBuildAction(new CodeBuildActionProps {
ActionName = "Lambda_Build",
Project = lambdaBuildProject,
Input = lambdaSourceOutput,
Outputs = new [] { lambdaBuildOutput }
});
pipeline.AddStage(new StageOptions {
StageName = "Build",
Actions = new [] { cdkBuildAction, lambdaBuildAction }
});
// finally, deploy your Lambda Stack
pipeline.AddStage(new StageOptions {
StageName = "Deploy",
Actions = new [] {
new CloudFormationCreateUpdateStackAction(new CloudFormationCreateUpdateStackActionProps {
ActionName = "Lambda_CFN_Deploy",
TemplatePath = cdkBuildOutput.AtPath("LambdaStack.template.yaml"),
StackName = "LambdaStackDeployedName",
AdminPermissions = true,
ParameterOverrides = lambdaCode.Assign(lambdaBuildOutput.S3Location),
ExtraInputs = new [] { lambdaBuildOutput }
}) }
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
lambdaStack := cdk.NewStack(app, jsii.String("LambdaStack"))
lambdaCode := lambda.Code_FromCfnParameters()
lambda.NewFunction(lambdaStack, jsii.String("Lambda"), &FunctionProps{
Code: lambdaCode,
Handler: jsii.String("index.handler"),
Runtime: lambda.Runtime_NODEJS_LATEST(),
})
// other resources that your Lambda needs, added to the lambdaStack...
pipelineStack := cdk.NewStack(app, jsii.String("PipelineStack"))
pipeline := codepipeline.NewPipeline(pipelineStack, jsii.String("Pipeline"), &PipelineProps{
CrossAccountKeys: jsii.Boolean(true),
})
// add the source code repository containing this code to your Pipeline,
// and the source code of the Lambda Function, if they're separate
cdkSourceOutput := codepipeline.NewArtifact()
cdkSourceAction := codepipeline_actions.NewCodeCommitSourceAction(&CodeCommitSourceActionProps{
Repository: codecommit.NewRepository(pipelineStack, jsii.String("CdkCodeRepo"), &RepositoryProps{
RepositoryName: jsii.String("CdkCodeRepo"),
}),
ActionName: jsii.String("CdkCode_Source"),
Output: cdkSourceOutput,
})
lambdaSourceOutput := codepipeline.NewArtifact()
lambdaSourceAction := codepipeline_actions.NewCodeCommitSourceAction(&CodeCommitSourceActionProps{
Repository: codecommit.NewRepository(pipelineStack, jsii.String("LambdaCodeRepo"), &RepositoryProps{
RepositoryName: jsii.String("LambdaCodeRepo"),
}),
ActionName: jsii.String("LambdaCode_Source"),
Output: lambdaSourceOutput,
})
pipeline.AddStage(&StageOptions{
StageName: jsii.String("Source"),
Actions: []IAction{
cdkSourceAction,
lambdaSourceAction,
},
})
// 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
cdkBuildProject := codebuild.NewProject(pipelineStack, jsii.String("CdkBuildProject"), &ProjectProps{
Environment: &BuildEnvironment{
BuildImage: codebuild.LinuxBuildImage_STANDARD_7_0(),
},
BuildSpec: codebuild.BuildSpec_FromObject(map[string]interface{}{
"version": jsii.String("0.2"),
"phases": map[string]map[string]*string{
"install": map[string]*string{
"commands": jsii.String("npm install"),
},
"build": map[string][]*string{
"commands": []*string{
jsii.String("npm run build"),
jsii.String("npm run cdk synth LambdaStack -- -o ."),
},
},
},
"artifacts": map[string]*string{
"files": jsii.String("LambdaStack.template.yaml"),
},
}),
})
cdkBuildOutput := codepipeline.NewArtifact()
cdkBuildAction := codepipeline_actions.NewCodeBuildAction(&CodeBuildActionProps{
ActionName: jsii.String("CDK_Build"),
Project: cdkBuildProject,
Input: cdkSourceOutput,
Outputs: []Artifact{
cdkBuildOutput,
},
})
// 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
lambdaBuildProject := codebuild.NewProject(pipelineStack, jsii.String("LambdaBuildProject"), &ProjectProps{
Environment: &BuildEnvironment{
BuildImage: codebuild.LinuxBuildImage_STANDARD_7_0(),
},
BuildSpec: codebuild.BuildSpec_*FromObject(map[string]interface{}{
"version": jsii.String("0.2"),
"phases": map[string]map[string]*string{
"install": map[string]*string{
"commands": jsii.String("npm install"),
},
"build": map[string]*string{
"commands": jsii.String("npm run build"),
},
},
"artifacts": map[string][]*string{
"files": []*string{
jsii.String("index.js"),
jsii.String("node_modules/**/*"),
},
},
}),
})
lambdaBuildOutput := codepipeline.NewArtifact()
lambdaBuildAction := codepipeline_actions.NewCodeBuildAction(&CodeBuildActionProps{
ActionName: jsii.String("Lambda_Build"),
Project: lambdaBuildProject,
Input: lambdaSourceOutput,
Outputs: []Artifact{
lambdaBuildOutput,
},
})
pipeline.AddStage(&StageOptions{
StageName: jsii.String("Build"),
Actions: []IAction{
cdkBuildAction,
lambdaBuildAction,
},
})
// finally, deploy your Lambda Stack
pipeline.AddStage(&StageOptions{
StageName: jsii.String("Deploy"),
Actions: []IAction{
codepipeline_actions.NewCloudFormationCreateUpdateStackAction(&CloudFormationCreateUpdateStackActionProps{
ActionName: jsii.String("Lambda_CFN_Deploy"),
TemplatePath: cdkBuildOutput.AtPath(jsii.String("LambdaStack.template.yaml")),
StackName: jsii.String("LambdaStackDeployedName"),
AdminPermissions: jsii.Boolean(true),
ParameterOverrides: lambdaCode.Assign(lambdaBuildOutput.s3Location),
ExtraInputs: []Artifact{
lambdaBuildOutput,
},
}),
},
})
Initializer
new CfnParametersCode(props?: CfnParametersCodeProps)
CfnParametersCode(props: typing.Optional[CfnParametersCodeProps] = None)
new CfnParametersCode(CfnParametersCodeProps props)
new CfnParametersCode(CfnParametersCodeProps? props = null)
NewCfnParametersCode(Props CfnParametersCodeProps)
Properties
Methods
assign(location: Location): { [key: string]: any }def assign(self, location: Location) -> typing.Mapping[str, Any]public Map<String, Object> assign(Location location)public IDictionary<string, object> Assign(Location location)func Assign(Location Location) *map[string]interface{}#notes · 1 parameter
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.
Parameters
locationlocationlocationlocationLocation— the location of the object in S3 that represents the Lambda code.
bind(scope: Construct): CodeConfigdef bind(self, scope: Construct) -> CodeConfigpublic CodeConfig bind(Construct scope)public CodeConfig Bind(Construct scope)func Bind(Scope Construct) CodeConfig#bindToResource(_resource: CfnResource, _options?: ResourceBindOptions): voiddef bind_to_resource(self, _resource: CfnResource, _options: typing.Optional[ResourceBindOptions] = None) -> Nonepublic void bindToResource(CfnResource _resource, ResourceBindOptions _options)public void BindToResource(CfnResource _resource, ResourceBindOptions? _options = null)func BindToResource(_resource CfnResource, _options ResourceBindOptions)#Specifically it's required to allow assets to add metadata for tooling like SAM CLI to be able to find their origins.
fromAsset(path: string, options?: AssetOptions): AssetCode@staticmethod def from_asset(path: str, options: typing.Optional[AssetOptions] = None) -> AssetCodepublic static AssetCode fromAsset(String path, AssetOptions options)public static AssetCode FromAsset(string path, AssetOptions? options = null)func FromAsset(Path *string, Options AssetOptions) AssetCodestatic#1 parameter
Parameters
pathpathpathpathPath— Either a directory with the Lambda code bundle or a .zip file.
fromAssetImage(directory: string, props?: AssetImageCodeProps): AssetImageCode@staticmethod def from_asset_image(directory: str, props: typing.Optional[AssetImageCodeProps] = None) -> AssetImageCodepublic static AssetImageCode fromAssetImage(String directory, AssetImageCodeProps props)public static AssetImageCode FromAssetImage(string directory, AssetImageCodeProps? props = null)func FromAssetImage(Directory *string, Props AssetImageCodeProps) AssetImageCodestatic#2 parameters
Parameters
directorydirectorydirectorydirectoryDirectory— the directory from which the asset must be created.propspropspropspropsProps— properties to further configure the selected image.
fromBucket(bucket: IBucket, key: string, objectVersion?: string): S3Code@staticmethod def from_bucket(bucket: IBucket, key: str, object_version: typing.Optional[str] = None) -> S3Codepublic static S3Code fromBucket(IBucket bucket, String key, String objectVersion)public static S3Code FromBucket(IBucket bucket, string key, string? objectVersion = null)func FromBucket(Bucket IBucket, Key *string, ObjectVersion *string) S3Codestatic#notes · 3 parameters
Note: If objectVersion is not defined, the lambda will not be updated automatically if the code in the bucket is updated. This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set objectVersion.
Parameters
bucketbucketbucketbucketBucket— The S3 bucket.keykeykeykeyKey— The object key.objectVersionobject_versionobjectVersionobjectVersionObjectVersion— Optional S3 object version.
fromBucketV2(bucket: IBucket, key: string, options?: BucketOptions): S3CodeV2@staticmethod def from_bucket_v2(bucket: IBucket, key: str, options: typing.Optional[BucketOptions] = None) -> S3CodeV2public static S3CodeV2 fromBucketV2(IBucket bucket, String key, BucketOptions options)public static S3CodeV2 FromBucketV2(IBucket bucket, string key, BucketOptions? options = null)func FromBucketV2(Bucket IBucket, Key *string, Options BucketOptions) S3CodeV2static#notes · 3 parameters
Note: If options.objectVersion is not defined, the lambda will not be updated automatically if the code in the bucket is updated. This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set objectVersion.
Parameters
bucketbucketbucketbucketBucket— The S3 bucket.keykeykeykeyKey— The object key.optionsoptionsoptionsoptionsOptions— Optional parameters for setting the code, current optional parameters to set here are 1.
fromCfnParameters(props?: CfnParametersCodeProps): CfnParametersCode // chainable@staticmethod def from_cfn_parameters(props: typing.Optional[CfnParametersCodeProps] = None) -> CfnParametersCodepublic static CfnParametersCode fromCfnParameters(CfnParametersCodeProps props)public static CfnParametersCode FromCfnParameters(CfnParametersCodeProps? props = null)func FromCfnParameters(Props CfnParametersCodeProps) CfnParametersCodestatic#1 parameter · returns
Parameters
propspropspropspropsProps— optional construction properties ofCfnParametersCode.
Returns: a new instance of CfnParametersCode
fromCustomCommand(output: string, command: string[], options?: CustomCommandOptions): AssetCode@staticmethod def from_custom_command(output: str, command: typing.List[str], options: typing.Optional[CustomCommandOptions] = None) -> AssetCodepublic static AssetCode fromCustomCommand(String output, List<String> command, CustomCommandOptions options)public static AssetCode FromCustomCommand(string output, string[] command, CustomCommandOptions? options = null)func FromCustomCommand(Output *string, Command *[]*string, Options CustomCommandOptions) AssetCodestatic#3 parameters
Parameters
outputoutputoutputoutputOutput— Where the output of the command will be directed, either a directory or a .zip file with the output Lambda code bundle * For example, if you use the command to run a build script (e.g., [ 'node', 'bundle_code.js' ]), and the build script generates a directory/my/lambda/codecontaining code that should be ran in a Lambda function, then output should be set to/my/lambda/code.commandcommandcommandcommandCommand— The command which will be executed to generate the output, for example, [ 'node', 'bundle_code.js' ].optionsoptionsoptionsoptionsOptions— options for the custom command, and other asset options -- but bundling options are not allowed.
fromDockerBuild(path: string, options?: DockerBuildAssetOptions): AssetCode@staticmethod def from_docker_build(path: str, options: typing.Optional[DockerBuildAssetOptions] = None) -> AssetCodepublic static AssetCode fromDockerBuild(String path, DockerBuildAssetOptions options)public static AssetCode FromDockerBuild(string path, DockerBuildAssetOptions? options = null)func FromDockerBuild(Path *string, Options DockerBuildAssetOptions) AssetCodestatic#By default, the asset is expected to be located at /asset in the image.
2 parameters
Parameters
pathpathpathpathPath— The path to the directory containing the Docker file.optionsoptionsoptionsoptionsOptions— Docker build options.
fromEcrImage(repository: IRepository, props?: EcrImageCodeProps): EcrImageCode@staticmethod def from_ecr_image(repository: IRepository, props: typing.Optional[EcrImageCodeProps] = None) -> EcrImageCodepublic static EcrImageCode fromEcrImage(IRepository repository, EcrImageCodeProps props)public static EcrImageCode FromEcrImage(IRepository repository, EcrImageCodeProps? props = null)func FromEcrImage(Repository IRepository, Props EcrImageCodeProps) EcrImageCodestatic#2 parameters
Parameters
repositoryrepositoryrepositoryrepositoryRepository— the ECR repository that the image is in.propspropspropspropsProps— properties to further configure the selected image.
fromInline(code: string): InlineCode@staticmethod def from_inline(code: str) -> InlineCodepublic static InlineCode fromInline(String code)public static InlineCode FromInline(string code)func FromInline(Code *string) InlineCodestatic#1 parameter · returns
Parameters
codecodecodecodeCode— The actual handler code (the resulting zip file cannot exceed 4MB).
Returns: LambdaInlineCode with inline code.