InlineCode¶
-
class
aws_cdk.aws_lambda.
InlineCode
(code)¶ Bases:
aws_cdk.aws_lambda.Code
Lambda code from an inline string (limited to 4KiB).
- Parameters
code (
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
-
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)¶ (deprecated) DEPRECATED.
- Parameters
path (
str
) –- Deprecated
use
fromAsset
- Stability
deprecated
- Return type
-
classmethod
bucket
(bucket, key, object_version=None)¶ (deprecated) DEPRECATED.
-
classmethod
cfn_parameters
(*, bucket_name_param=None, object_key_param=None)¶ (deprecated) DEPRECATED.
- 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 createdobject_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
-
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 useasset.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 excludedfollow (
Optional
[FollowMode
]) – (deprecated) A strategy for how to handle symlinks. Default: Neverignore_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. IfassetHashType
is set it must be set toAssetHashType.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 onassetHashType
asset_hash_type (
Optional
[AssetHashType
]) – Specifies the type of hash to calculate for this asset. IfassetHash
is configured, this option must beundefined
orAssetHashType.CUSTOM
. Default: - the default isAssetHashType.SOURCE
, but ifassetHash
is explicitly specified this value defaults toAssetHashType.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
-
classmethod
from_asset_image
(directory, *, cmd=None, entrypoint=None, build_args=None, file=None, repository_name=None, target=None, extra_hash=None, exclude=None, follow=None, ignore_mode=None)¶ Create an ECR image from the specified asset and bind it as the Lambda code.
- Parameters
directory (
str
) – the directory from which the asset must be created.cmd (
Optional
[List
[str
]]) – Specify or override the CMD on the specified Docker image or Dockerfile. This needs to be in the ‘exec form’, viz.,[ 'executable', 'param1', 'param2' ]
. Default: - use the CMD specified in the docker image or Dockerfile.entrypoint (
Optional
[List
[str
]]) – Specify or override the ENTRYPOINT on the specified Docker image or Dockerfile. An ENTRYPOINT allows you to configure a container that will run as an executable. This needs to be in the ‘exec form’, viz.,[ 'executable', 'param1', 'param2' ]
. Default: - use the ENTRYPOINT in the docker image or Dockerfile.build_args (
Optional
[Mapping
[str
,str
]]) – (experimental) Build args to pass to thedocker build
command. Since Docker build arguments are resolved before deployment, keys and values cannot refer to unresolved tokens (such aslambda.functionArn
orqueue.queueUrl
). Default: - no build args are passedfile (
Optional
[str
]) – (experimental) Path to the Dockerfile (relative to the directory). Default: ‘Dockerfile’repository_name (
Optional
[str
]) – (deprecated) ECR repository name. Specify this property if you need to statically address the image, e.g. from a Kubernetes Pod. Note, this is only the repository name, without the registry and the tag parts. Default: - the default ECR repository for CDK assetstarget (
Optional
[str
]) – (experimental) Docker target to build to. Default: - no targetextra_hash (
Optional
[str
]) – (deprecated) Extra information to encode into the fingerprint (e.g. build instructions and other inputs). Default: - hash is only based on source contentexclude (
Optional
[List
[str
]]) – (deprecated) Glob patterns to exclude from the copy. Default: nothing is excludedfollow (
Optional
[FollowMode
]) – (deprecated) A strategy for how to handle symlinks. Default: Neverignore_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 ‘
- Return type
-
classmethod
from_bucket
(bucket, key, object_version=None)¶ Lambda handler code as an 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 createdobject_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
- Returns
a new instance of
CfnParametersCode
-
classmethod
from_ecr_image
(repository, *, cmd=None, entrypoint=None, tag=None)¶ Use an existing ECR image as the Lambda code.
- Parameters
repository (
IRepository
) – the ECR repository that the image is in.cmd (
Optional
[List
[str
]]) – Specify or override the CMD on the specified Docker image or Dockerfile. This needs to be in the ‘exec form’, viz.,[ 'executable', 'param1', 'param2' ]
. Default: - use the CMD specified in the docker image or Dockerfile.entrypoint (
Optional
[List
[str
]]) – Specify or override the ENTRYPOINT on the specified Docker image or Dockerfile. An ENTRYPOINT allows you to configure a container that will run as an executable. This needs to be in the ‘exec form’, viz.,[ 'executable', 'param1', 'param2' ]
. Default: - use the ENTRYPOINT in the docker image or Dockerfile.tag (
Optional
[str
]) – The image tag to use when pulling the image from ECR. Default: ‘latest’
- Return type
-
classmethod
from_inline
(code)¶ Inline code for Lambda handler.
- Parameters
code (
str
) – The actual handler code (limited to 4KiB).- Return type
- Returns
LambdaInlineCode
with inline code.
-
classmethod
inline
(code)¶ (deprecated) DEPRECATED.
- Parameters
code (
str
) –- Deprecated
use
fromInline
- Stability
deprecated
- Return type