Code

class aws_cdk.aws_lambda.Code

Bases: object

__init__()

Initialize self. See help(type(self)) for accurate signature.

Return type

None

Methods

bind(scope)

Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.

Parameters

scope (Construct) – The binding scope. Don’t be smart about trying to down-cast or assume it’s initialized. You may just use it as a construct scope.

Return type

CodeConfig

bind_to_resource(_resource, *, resource_property=None)

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.

Parameters
  • _resource (CfnResource) –

  • resource_property (Optional[str]) – The name of the CloudFormation property to annotate with asset metadata. Default: Code

Return type

None

Attributes

is_inline

Determines whether this Code is inline code or not.

deprecated :deprecated:

this value is ignored since inline is now determined based on the the inlineCode field of CodeConfig returned from bind().

stability :stability: deprecated

Return type

bool

Static Methods

classmethod asset(path)
Parameters

path (str) –

deprecated :deprecated: use fromAsset

stability :stability: deprecated

Return type

AssetCode

classmethod bucket(bucket, key, object_version=None)
Parameters
  • bucket (IBucket) –

  • key (str) –

  • object_version (Optional[str]) –

deprecated :deprecated: use fromBucket

stability :stability: deprecated

Return type

S3Code

classmethod cfn_parameters(*, bucket_name_param=None, object_key_param=None)
Parameters
  • bucket_name_param (Optional[CfnParameter]) – The CloudFormation parameter that represents the name of the S3 Bucket where the Lambda code will be located in. Must be of type ‘String’. Default: a new parameter will be created

  • object_key_param (Optional[CfnParameter]) – The CloudFormation parameter that represents the path inside the S3 Bucket where the Lambda code will be located at. Must be of type ‘String’. Default: a new parameter will be created

deprecated :deprecated: use fromCfnParameters

stability :stability: deprecated

Return type

CfnParametersCode

classmethod from_asset(path, *, readers=None, source_hash=None, exclude=None, follow=None)

Loads the function code from a local disk asset.

Parameters
  • path (str) – Either a directory with the Lambda code bundle or a .zip file.

  • readers (Optional[List[IGrantable]]) – A list of principals that should be able to read this asset from S3. You can use asset.grantRead(principal) to grant read permissions later. Default: - No principals that can read file asset.

  • source_hash (Optional[str]) – Custom source hash to use when identifying the specific version of the asset. NOTE: the source hash is used in order to identify a specific revision of the asset, and used for optimizing and caching deployment activities related to this asset such as packaging, uploading to Amazon S3, etc. If you chose to customize the source hash, you will need to make sure it is updated every time the source changes, or otherwise it is possible that some deployments will not be invalidated. Default: - automatically calculate source hash based on the contents of the source file or directory.

  • exclude (Optional[List[str]]) – Glob patterns to exclude from the copy. Default: nothing is excluded

  • follow (Optional[FollowMode]) – A strategy for how to handle symlinks. Default: Never

Return type

AssetCode

classmethod from_bucket(bucket, key, object_version=None)
Parameters
  • bucket (IBucket) – The S3 bucket.

  • key (str) – The object key.

  • object_version (Optional[str]) – Optional S3 object version.

return :rtype: S3Code :return: LambdaS3Code associated with the specified S3 object.

classmethod from_cfn_parameters(*, bucket_name_param=None, object_key_param=None)

Creates a new Lambda source defined using CloudFormation parameters.

Parameters
  • bucket_name_param (Optional[CfnParameter]) – The CloudFormation parameter that represents the name of the S3 Bucket where the Lambda code will be located in. Must be of type ‘String’. Default: a new parameter will be created

  • object_key_param (Optional[CfnParameter]) – The CloudFormation parameter that represents the path inside the S3 Bucket where the Lambda code will be located at. Must be of type ‘String’. Default: a new parameter will be created

return :rtype: CfnParametersCode :return: a new instance of CfnParametersCode

classmethod from_inline(code)
Parameters

code (str) – The actual handler code (limited to 4KiB).

return :rtype: InlineCode :return: LambdaInlineCode with inline code.

classmethod inline(code)
Parameters

code (str) –

deprecated :deprecated: use fromInline

stability :stability: deprecated

Return type

InlineCode