S3Code

class aws_cdk.aws_lambda.S3Code(bucket, key, object_version=None)

Bases: aws_cdk.aws_lambda.Code

Lambda code from an S3 archive.

Parameters
  • bucket (IBucket) –

  • key (str) –

  • object_version (Optional[str]) –

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) –

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.

Return type

bool

Static Methods

classmethod asset(path)
Parameters

path (str) –

Deprecated

use fromAsset

Stability

deprecated

Return type

AssetCode

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

  • key (str) –

  • object_version (Optional[str]) –

Deprecated

use fromBucket

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

use fromCfnParameters

Stability

deprecated

Return type

CfnParametersCode

classmethod from_asset(path, *, readers=None, source_hash=None, exclude=None, follow=None, ignore_mode=None, asset_hash=None, asset_hash_type=None, bundling=None)

Loads the function code from a local disk path.

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

  • readers (Optional[List[IGrantable]]) – (experimental) 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]) – (deprecated) Custom hash to use when identifying the specific version of the asset. For consistency, this custom hash will be SHA256 hashed and encoded as hex. The resulting hash will be the asset hash. 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]]) – (deprecated) Glob patterns to exclude from the copy. Default: nothing is excluded

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

  • ignore_mode (Optional[IgnoreMode]) – (deprecated) The ignore behavior to use for exclude patterns. Default: - GLOB for file assets, DOCKER or GLOB for docker assets depending on whether the ‘

  • asset_hash (Optional[str]) – Specify a custom hash for this asset. If assetHashType is set it must be set to AssetHashType.CUSTOM. For consistency, this custom hash will be SHA256 hashed and encoded as hex. The resulting hash will be the asset hash. NOTE: the 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 hash, you will need to make sure it is updated every time the asset changes, or otherwise it is possible that some deployments will not be invalidated. Default: - based on assetHashType

  • asset_hash_type (Optional[AssetHashType]) – Specifies the type of hash to calculate for this asset. If assetHash is configured, this option must be undefined or AssetHashType.CUSTOM. Default: - the default is AssetHashType.SOURCE, but if assetHash is explicitly specified this value defaults to AssetHashType.CUSTOM.

  • bundling (Optional[BundlingOptions]) – (experimental) Bundle the asset by executing a command in a Docker container. The asset path will be mounted at /asset-input. The Docker container is responsible for putting content at /asset-output. The content at /asset-output will be zipped and used as the final asset. Default: - uploaded as-is to S3 if the asset is a regular file or a .zip file, archived into a .zip file and uploaded to S3 otherwise

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 type

S3Code

Returns

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 type

CfnParametersCode

Returns

a new instance of CfnParametersCode

classmethod from_inline(code)
Parameters

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

Return type

InlineCode

Returns

LambdaInlineCode with inline code.

classmethod inline(code)
Parameters

code (str) –

Deprecated

use fromInline

Stability

deprecated

Return type

InlineCode