Class: AWSCDK::Lambda::Code
- Inherits:
-
Jsii::Object
- Object
- Jsii::Object
- AWSCDK::Lambda::Code
- Defined in:
- lambda/code.rb
Overview
Represents the Lambda Handler Code.
Direct Known Subclasses
AssetCode, AssetImageCode, CfnParametersCode, ECRImageCode, InlineCode, S3Code, S3CodeV2
Class Method Summary collapse
-
.from_asset(path, options = nil) ⇒ AWSCDK::Lambda::AssetCode
Loads the function code from a local disk path.
-
.from_asset_image(directory, props = nil) ⇒ AWSCDK::Lambda::AssetImageCode
Create an ECR image from the specified asset and bind it as the Lambda code.
-
.from_bucket(bucket, key, object_version = nil) ⇒ AWSCDK::Lambda::S3Code
Lambda handler code as an S3 object.
-
.from_bucket_v2(bucket, key, options = nil) ⇒ AWSCDK::Lambda::S3CodeV2
Lambda handler code as an S3 object.
-
.from_cfn_parameters(props = nil) ⇒ AWSCDK::Lambda::CfnParametersCode
Creates a new Lambda source defined using CloudFormation parameters.
-
.from_custom_command(output, command, options = nil) ⇒ AWSCDK::Lambda::AssetCode
Runs a command to build the code asset that will be used.
-
.from_docker_build(path, options = nil) ⇒ AWSCDK::Lambda::AssetCode
Loads the function code from an asset created by a Docker build.
-
.from_ecr_image(repository, props = nil) ⇒ AWSCDK::Lambda::ECRImageCode
Use an existing ECR image as the Lambda code.
-
.from_inline(code) ⇒ AWSCDK::Lambda::InlineCode
Inline code for Lambda handler.
- .jsii_overridable_methods ⇒ Object
Instance Method Summary collapse
-
#bind(scope) ⇒ AWSCDK::Lambda::CodeConfig
Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
-
#bind_to_resource(_resource, _options = nil) ⇒ void
Called after the CFN function resource has been created to allow the code class to bind to it.
-
#initialize ⇒ Code
constructor
A new instance of Code.
Constructor Details
#initialize ⇒ Code
Returns a new instance of Code.
8 9 10 |
# File 'lambda/code.rb', line 8 def initialize Jsii::Object.instance_method(:initialize).bind(self).call end |
Class Method Details
.from_asset(path, options = nil) ⇒ AWSCDK::Lambda::AssetCode
Loads the function code from a local disk path.
24 25 26 27 28 29 |
# File 'lambda/code.rb', line 24 def self.from_asset(path, = nil) Jsii::Type.check_type(path, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "path") = .is_a?(Hash) ? ::AWSCDK::S3Assets::AssetOptions.new(**.transform_keys(&:to_sym)) : Jsii::Type.check_type(, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfczNfYXNzZXRzLkFzc2V0T3B0aW9ucyJ9")), "options") unless .nil? Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Code", "fromAsset", [path, ]) end |
.from_asset_image(directory, props = nil) ⇒ AWSCDK::Lambda::AssetImageCode
Create an ECR image from the specified asset and bind it as the Lambda code.
36 37 38 39 40 41 |
# File 'lambda/code.rb', line 36 def self.from_asset_image(directory, props = nil) Jsii::Type.check_type(directory, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "directory") props = props.is_a?(Hash) ? ::AWSCDK::Lambda::AssetImageCodeProps.new(**props.transform_keys(&:to_sym)) : props Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkFzc2V0SW1hZ2VDb2RlUHJvcHMifQ==")), "props") unless props.nil? Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Code", "fromAssetImage", [directory, props]) end |
.from_bucket(bucket, key, object_version = nil) ⇒ AWSCDK::Lambda::S3Code
Lambda handler code as an S3 object.
Note: If object_version 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.
52 53 54 55 56 57 |
# File 'lambda/code.rb', line 52 def self.from_bucket(bucket, key, object_version = nil) Jsii::Type.check_type(bucket, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfczMuSUJ1Y2tldCJ9")), "bucket") Jsii::Type.check_type(key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "key") Jsii::Type.check_type(object_version, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "objectVersion") unless object_version.nil? Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Code", "fromBucket", [bucket, key, object_version]) end |
.from_bucket_v2(bucket, key, options = nil) ⇒ AWSCDK::Lambda::S3CodeV2
Lambda handler code as an S3 object.
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.
68 69 70 71 72 73 74 |
# File 'lambda/code.rb', line 68 def self.from_bucket_v2(bucket, key, = nil) Jsii::Type.check_type(bucket, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfczMuSUJ1Y2tldCJ9")), "bucket") Jsii::Type.check_type(key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "key") = .is_a?(Hash) ? ::AWSCDK::Lambda::BucketOptions.new(**.transform_keys(&:to_sym)) : Jsii::Type.check_type(, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkJ1Y2tldE9wdGlvbnMifQ==")), "options") unless .nil? Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Code", "fromBucketV2", [bucket, key, ]) end |
.from_cfn_parameters(props = nil) ⇒ AWSCDK::Lambda::CfnParametersCode
Creates a new Lambda source defined using CloudFormation parameters.
80 81 82 83 84 |
# File 'lambda/code.rb', line 80 def self.from_cfn_parameters(props = nil) props = props.is_a?(Hash) ? ::AWSCDK::Lambda::CfnParametersCodeProps.new(**props.transform_keys(&:to_sym)) : props Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkNmblBhcmFtZXRlcnNDb2RlUHJvcHMifQ==")), "props") unless props.nil? Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Code", "fromCfnParameters", [props]) end |
.from_custom_command(output, command, options = nil) ⇒ AWSCDK::Lambda::AssetCode
Runs a command to build the code asset that will be used.
92 93 94 95 96 97 98 |
# File 'lambda/code.rb', line 92 def self.from_custom_command(output, command, = nil) Jsii::Type.check_type(output, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "output") Jsii::Type.check_type(command, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6InN0cmluZyJ9LCJraW5kIjoiYXJyYXkifX0=")), "command") = .is_a?(Hash) ? ::AWSCDK::Lambda::CustomCommandOptions.new(**.transform_keys(&:to_sym)) : Jsii::Type.check_type(, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkN1c3RvbUNvbW1hbmRPcHRpb25zIn0=")), "options") unless .nil? Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Code", "fromCustomCommand", [output, command, ]) end |
.from_docker_build(path, options = nil) ⇒ AWSCDK::Lambda::AssetCode
Loads the function code from an asset created by a Docker build.
By default, the asset is expected to be located at /asset in the
image.
108 109 110 111 112 113 |
# File 'lambda/code.rb', line 108 def self.from_docker_build(path, = nil) Jsii::Type.check_type(path, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "path") = .is_a?(Hash) ? ::AWSCDK::Lambda::DockerBuildAssetOptions.new(**.transform_keys(&:to_sym)) : Jsii::Type.check_type(, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkRvY2tlckJ1aWxkQXNzZXRPcHRpb25zIn0=")), "options") unless .nil? Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Code", "fromDockerBuild", [path, ]) end |
.from_ecr_image(repository, props = nil) ⇒ AWSCDK::Lambda::ECRImageCode
Use an existing ECR image as the Lambda code.
120 121 122 123 124 125 |
# File 'lambda/code.rb', line 120 def self.from_ecr_image(repository, props = nil) Jsii::Type.check_type(repository, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWNyLklSZXBvc2l0b3J5In0=")), "repository") props = props.is_a?(Hash) ? ::AWSCDK::Lambda::ECRImageCodeProps.new(**props.transform_keys(&:to_sym)) : props Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLkVjckltYWdlQ29kZVByb3BzIn0=")), "props") unless props.nil? Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Code", "fromEcrImage", [repository, props]) end |
.from_inline(code) ⇒ AWSCDK::Lambda::InlineCode
Inline code for Lambda handler.
131 132 133 134 |
# File 'lambda/code.rb', line 131 def self.from_inline(code) Jsii::Type.check_type(code, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "code") Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_lambda.Code", "fromInline", [code]) end |
.jsii_overridable_methods ⇒ Object
12 13 14 15 16 17 |
# File 'lambda/code.rb', line 12 def self.jsii_overridable_methods { :bind => { kind: :method, name: "bind", is_optional: false }, :bind_to_resource => { kind: :method, name: "bindToResource", is_optional: false }, } end |
Instance Method Details
#bind(scope) ⇒ AWSCDK::Lambda::CodeConfig
Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
140 141 142 143 |
# File 'lambda/code.rb', line 140 def bind(scope) Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope") jsii_call_method("bind", [scope]) end |
#bind_to_resource(_resource, _options = nil) ⇒ void
This method returns an undefined value.
Called after the CFN function resource has been created to allow the code class to bind to it.
Specifically it's required to allow assets to add metadata for tooling like SAM CLI to be able to find their origins.
153 154 155 156 157 158 |
# File 'lambda/code.rb', line 153 def bind_to_resource(_resource, = nil) Jsii::Type.check_type(_resource, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5DZm5SZXNvdXJjZSJ9")), "_resource") = .is_a?(Hash) ? ::AWSCDK::Lambda::ResourceBindOptions.new(**.transform_keys(&:to_sym)) : Jsii::Type.check_type(, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfbGFtYmRhLlJlc291cmNlQmluZE9wdGlvbnMifQ==")), "_options") unless .nil? jsii_call_method("bindToResource", [_resource, ]) end |