Class: AWSCDK::Lambda::CfnFunction::CodeProperty

Inherits:
Jsii::Struct
  • Object
show all
Defined in:
lambda/cfn_function.rb

Overview

The deployment package for a Lambda function. To deploy a function defined as a container image, you specify the location of a container image in the Amazon ECR registry. For a .zip file deployment package, you can specify the location of an object in Amazon S3. For Node.js and Python functions, you can specify the function code inline in the template.

When you specify source code inline for a Node.js function, the index file that CloudFormation creates uses the extension .js . This means that Node.js treats the file as a CommonJS module.

Changes to a deployment package in Amazon S3 or a container image in ECR are not detected automatically during stack updates. To update the function code, change the object key or version in the template.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image_uri: nil, s3_bucket: nil, s3_key: nil, s3_object_version: nil, source_kms_key_arn: nil, zip_file: nil) ⇒ CodeProperty

Returns a new instance of CodeProperty.

Parameters:

  • image_uri (String, nil) (defaults to: nil)

    URI of a container image in the Amazon ECR registry.

  • s3_bucket (String, nil) (defaults to: nil)

    An Amazon S3 bucket in the same AWS Region as your function.

  • s3_key (String, nil) (defaults to: nil)

    The Amazon S3 key of the deployment package.

  • s3_object_version (String, nil) (defaults to: nil)

    For versioned objects, the version of the deployment package object to use.

  • source_kms_key_arn (String, nil) (defaults to: nil)

    The ARN of the AWS Key Management Service ( AWS ) customer managed key that's used to encrypt your function's .zip deployment package. If you don't provide a customer managed key, Lambda uses an AWS owned key .

  • zip_file (String, nil) (defaults to: nil)

    (Node.js and Python) The source code of your Lambda function. If you include your function source inline with this parameter, CloudFormation places it in a file named index and zips it to create a deployment package . This zip file cannot exceed 4MB. For the Handler property, the first part of the handler identifier must be index . For example, index.handler .



1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
# File 'lambda/cfn_function.rb', line 1027

def initialize(image_uri: nil, s3_bucket: nil, s3_key: nil, s3_object_version: nil, source_kms_key_arn: nil, zip_file: nil)
  @image_uri = image_uri
  Jsii::Type.check_type(@image_uri, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "imageUri") unless @image_uri.nil?
  @s3_bucket = s3_bucket
  Jsii::Type.check_type(@s3_bucket, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "s3Bucket") unless @s3_bucket.nil?
  @s3_key = s3_key
  Jsii::Type.check_type(@s3_key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "s3Key") unless @s3_key.nil?
  @s3_object_version = s3_object_version
  Jsii::Type.check_type(@s3_object_version, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "s3ObjectVersion") unless @s3_object_version.nil?
  @source_kms_key_arn = source_kms_key_arn
  Jsii::Type.check_type(@source_kms_key_arn, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "sourceKmsKeyArn") unless @source_kms_key_arn.nil?
  @zip_file = zip_file
  Jsii::Type.check_type(@zip_file, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "zipFile") unless @zip_file.nil?
end

Instance Attribute Details

#image_uriString? (readonly)

URI of a container image in the Amazon ECR registry.



1046
1047
1048
# File 'lambda/cfn_function.rb', line 1046

def image_uri
  @image_uri
end

#s3_bucketString? (readonly)

An Amazon S3 bucket in the same AWS Region as your function.

The bucket can be in a different AWS account .



1053
1054
1055
# File 'lambda/cfn_function.rb', line 1053

def s3_bucket
  @s3_bucket
end

#s3_keyString? (readonly)

The Amazon S3 key of the deployment package.



1058
1059
1060
# File 'lambda/cfn_function.rb', line 1058

def s3_key
  @s3_key
end

#s3_object_versionString? (readonly)

For versioned objects, the version of the deployment package object to use.



1063
1064
1065
# File 'lambda/cfn_function.rb', line 1063

def s3_object_version
  @s3_object_version
end

#source_kms_key_arnString? (readonly)

The ARN of the AWS Key Management Service ( AWS ) customer managed key that's used to encrypt your function's .zip deployment package. If you don't provide a customer managed key, Lambda uses an AWS owned key .



1068
1069
1070
# File 'lambda/cfn_function.rb', line 1068

def source_kms_key_arn
  @source_kms_key_arn
end

#zip_fileString? (readonly)

(Node.js and Python) The source code of your Lambda function. If you include your function source inline with this parameter, CloudFormation places it in a file named index and zips it to create a deployment package . This zip file cannot exceed 4MB. For the Handler property, the first part of the handler identifier must be index . For example, index.handler .

When you specify source code inline for a Node.js function, the index file that CloudFormation creates uses the extension .js . This means that Node.js treats the file as a CommonJS module.

When using Node.js 24 or later, Node.js can automatically detect if a .js file should be treated as CommonJS or as an ES module. To enable auto-detection, add the --experimental-detect-module flag to the NODE_OPTIONS environment variable. For more information, see Experimental Node.js features .

For JSON, you must escape quotes and special characters such as newline ( \n ) with a backslash.

If you specify a function that interacts with an AWS CloudFormation custom resource, you don't have to write your own functions to send responses to the custom resource that invoked the function. AWS CloudFormation provides a response module ( cfn-response ) that simplifies sending responses. See Using AWS Lambda with AWS CloudFormation for details.



1081
1082
1083
# File 'lambda/cfn_function.rb', line 1081

def zip_file
  @zip_file
end

Class Method Details

.jsii_propertiesObject



1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
# File 'lambda/cfn_function.rb', line 1083

def self.jsii_properties
  {
    :image_uri => "imageUri",
    :s3_bucket => "s3Bucket",
    :s3_key => "s3Key",
    :s3_object_version => "s3ObjectVersion",
    :source_kms_key_arn => "sourceKmsKeyArn",
    :zip_file => "zipFile",
  }
end

Instance Method Details

#to_jsiiObject



1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
# File 'lambda/cfn_function.rb', line 1094

def to_jsii
  result = {}
  result.merge!({
    "imageUri" => @image_uri,
    "s3Bucket" => @s3_bucket,
    "s3Key" => @s3_key,
    "s3ObjectVersion" => @s3_object_version,
    "sourceKmsKeyArn" => @source_kms_key_arn,
    "zipFile" => @zip_file,
  })
  result.compact
end