create_function¶
Operation¶
create_function
async
¶
create_function(input: CreateFunctionInput, plugins: list[Plugin] | None = None) -> CreateFunctionOutput
Creates a Lambda function. To create a function, you need a deployment package and an execution role. The deployment package is a .zip file archive or container image that contains your function code. The execution role grants the function permission to use Amazon Web Services services, such as Amazon CloudWatch Logs for log streaming and X-Ray for request tracing.
If the deployment package is a container
image,
then you set the package type to Image. For a container image, the
code property must include the URI of a container image in the Amazon
ECR registry. You do not need to specify the handler and runtime
properties.
If the deployment package is a .zip file
archive,
then you set the package type to Zip. For a .zip file archive, the
code property specifies the location of the .zip file. You must also
specify the handler and runtime properties. The code in the deployment
package must be compatible with the target instruction set architecture
of the function (x86-64 or arm64). If you do not specify the
architecture, then the default value is x86-64.
When you create a function, Lambda provisions an instance of the
function and its supporting resources. If your function connects to a
VPC, this process can take a minute or so. During this time, you can't
invoke or modify the function. The State, StateReason, and
StateReasonCode fields in the response from GetFunctionConfiguration
indicate when the function is ready to invoke. For more information, see
Lambda function
states.
A function has an unpublished version, and can have published versions
and aliases. The unpublished version changes when you update your
function's code and configuration. A published version is a snapshot of
your function code and configuration that can't be changed. An alias is
a named resource that maps to a version, and can be changed to map to a
different version. Use the Publish parameter to create version 1 of
your function from its initial configuration.
The other parameters let you configure version-specific and function-level settings. You can modify version-specific settings later with UpdateFunctionConfiguration. Function-level settings apply to both the unpublished and published versions of the function, and include tags (TagResource) and per-function concurrency limits (PutFunctionConcurrency).
You can use code signing if your deployment package is a .zip file archive. To enable code signing for this function, specify the ARN of a code-signing configuration. When a user attempts to deploy a code package with UpdateFunctionCode, Lambda checks that the code package has a valid signature from a trusted publisher. The code-signing configuration includes set of signing profiles, which define the trusted publishers for this function.
If another Amazon Web Services account or an Amazon Web Services service invokes your function, use AddPermission to grant permission by creating a resource-based Identity and Access Management (IAM) policy. You can grant permissions at the function level, on a version, or on an alias.
To invoke your function directly, use Invoke. To invoke your function in response to events in other Amazon Web Services services, create an event source mapping (CreateEventSourceMapping), or configure a function trigger in the other service. For more information, see Invoking Lambda functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
CreateFunctionInput
|
An instance of |
required |
plugins
|
list[Plugin] | None
|
A list of callables that modify the configuration dynamically. Changes made by these plugins only apply for the duration of the operation execution and will not affect any other operation invocations. |
None
|
Returns:
| Type | Description |
|---|---|
CreateFunctionOutput
|
An instance of |
Input¶
CreateFunctionInput
dataclass
¶
Dataclass for CreateFunctionInput structure.
Attributes¶
architectures
class-attribute
instance-attribute
¶
architectures: list[Architecture] | None = None
The instruction set architecture that the function supports. Enter a
string array with one of the valid values (arm64 or x86_64). The default
value is x86_64.
capacity_provider_config
class-attribute
instance-attribute
¶
capacity_provider_config: CapacityProviderConfig | None = None
Configuration for the capacity provider that manages compute resources for Lambda functions.
code
class-attribute
instance-attribute
¶
code: FunctionCode | None = None
The code for the function.
code_signing_config_arn
class-attribute
instance-attribute
¶
code_signing_config_arn: str | None = None
To enable code signing for this function, specify the ARN of a code-signing configuration. A code-signing configuration includes a set of signing profiles, which define the trusted publishers for this function.
dead_letter_config
class-attribute
instance-attribute
¶
dead_letter_config: DeadLetterConfig | None = None
A dead-letter queue configuration that specifies the queue or topic where Lambda sends asynchronous events when they fail processing. For more information, see Dead-letter queues.
description
class-attribute
instance-attribute
¶
description: str | None = None
A description of the function.
durable_config
class-attribute
instance-attribute
¶
durable_config: DurableConfig | None = None
Configuration settings for durable functions. Enables creating functions with durability that can remember their state and continue execution even after interruptions.
environment
class-attribute
instance-attribute
¶
environment: Environment | None = None
Environment variables that are accessible from function code during execution.
ephemeral_storage
class-attribute
instance-attribute
¶
ephemeral_storage: EphemeralStorage | None = None
The size of the function's /tmp directory in MB. The default value is
512, but can be any whole number between 512 and 10,240 MB. For more
information, see Configuring ephemeral storage
(console).
file_system_configs
class-attribute
instance-attribute
¶
file_system_configs: list[FileSystemConfig] | None = None
Connection settings for an Amazon EFS file system or an Amazon S3 Files file system.
function_name
class-attribute
instance-attribute
¶
function_name: str | None = None
The name or ARN of the Lambda function.
Name formats
-
Function name --
my-function. -
Function ARN --
arn:aws:lambda:us-west-2:123456789012:function:my-function. -
Partial ARN --
123456789012:function:my-function.
The length constraint applies only to the full ARN. If you specify only the function name, it is limited to 64 characters in length.
handler
class-attribute
instance-attribute
¶
handler: str | None = None
The name of the method within your code that Lambda calls to run your function. Handler is required if the deployment package is a .zip file archive. The format includes the file name. It can also include namespaces and other qualifiers, depending on the runtime. For more information, see Lambda programming model.
image_config
class-attribute
instance-attribute
¶
image_config: ImageConfig | None = None
Container image configuration values that override the values in the container image Dockerfile.
kms_key_arn
class-attribute
instance-attribute
¶
kms_key_arn: str | None = None
The ARN of the Key Management Service (KMS) customer managed key that's used to encrypt the following resources:
-
The function's environment variables.
-
The function's Lambda SnapStart snapshots.
-
When used with
SourceKMSKeyArn, the unzipped version of the .zip deployment package that's used for function invocations. For more information, see Specifying a customer managed key for Lambda. -
The optimized version of the container image that's used for function invocations. Note that this is not the same key that's used to protect your container image in the Amazon Elastic Container Registry (Amazon ECR). For more information, see Function lifecycle.
If you don't provide a customer managed key, Lambda uses an Amazon Web Services owned key or an Amazon Web Services managed key.
layers
class-attribute
instance-attribute
¶
layers: list[str] | None = None
A list of function layers to add to the function's execution environment. Specify each layer by its ARN, including the version.
logging_config
class-attribute
instance-attribute
¶
logging_config: LoggingConfig | None = None
The function's Amazon CloudWatch Logs configuration settings.
memory_size
class-attribute
instance-attribute
¶
memory_size: int | None = None
The amount of memory available to the function at runtime. Increasing the function memory also increases its CPU allocation. The default value is 128 MB. The value can be any multiple of 1 MB.
package_type
class-attribute
instance-attribute
¶
package_type: PackageType | None = None
The type of deployment package. Set to Image for container image and
set to Zip for .zip file archive.
publish
class-attribute
instance-attribute
¶
publish: bool = False
Set to true to publish the first version of the function during creation.
publish_to
class-attribute
instance-attribute
¶
publish_to: FunctionVersionLatestPublished | None = None
Specifies where to publish the function version or configuration.
role
class-attribute
instance-attribute
¶
role: str | None = None
The Amazon Resource Name (ARN) of the function's execution role.
runtime
class-attribute
instance-attribute
¶
runtime: Runtime | None = None
The identifier of the function's runtime. Runtime is required if the deployment package is a .zip file archive. Specifying a runtime results in an error if you're deploying a function using a container image.
The following list includes deprecated runtimes. Lambda blocks creating new functions and updating existing functions shortly after each runtime is deprecated. For more information, see Runtime use after deprecation.
For a list of all currently supported runtimes, see Supported runtimes.
snap_start
class-attribute
instance-attribute
¶
snap_start: SnapStart | None = None
The function's SnapStart setting.
tags
class-attribute
instance-attribute
¶
tags: dict[str, str] | None = None
A list of tags to apply to the function.
tenancy_config
class-attribute
instance-attribute
¶
tenancy_config: TenancyConfig | None = None
Configuration for multi-tenant applications that use Lambda functions. Defines tenant isolation settings and resource allocations. Required for functions supporting multiple tenants.
timeout
class-attribute
instance-attribute
¶
timeout: int | None = None
The amount of time (in seconds) that Lambda allows a function to run before stopping it. The default is 3 seconds. The maximum allowed value is 900 seconds. For more information, see Lambda execution environment.
tracing_config
class-attribute
instance-attribute
¶
tracing_config: TracingConfig | None = None
Set Mode to Active to sample and trace a subset of incoming requests
with
X-Ray.
vpc_config
class-attribute
instance-attribute
¶
vpc_config: VpcConfig | None = None
For network connectivity to Amazon Web Services resources in a VPC, specify a list of security groups and subnets in the VPC. When you connect a function to a VPC, it can access resources and the internet only through that VPC. For more information, see Configuring a Lambda function to access resources in a VPC.
Output¶
CreateFunctionOutput
dataclass
¶
Details about a function's configuration.
Attributes¶
architectures
class-attribute
instance-attribute
¶
architectures: list[Architecture] | None = None
The instruction set architecture that the function supports.
Architecture is a string array with one of the valid values. The default
architecture value is x86_64.
capacity_provider_config
class-attribute
instance-attribute
¶
capacity_provider_config: CapacityProviderConfig | None = None
Configuration for the capacity provider that manages compute resources for Lambda functions.
code_sha256
class-attribute
instance-attribute
¶
code_sha256: str | None = None
The SHA256 hash of the function's deployment package.
code_size
class-attribute
instance-attribute
¶
code_size: int = 0
The size of the function's deployment package, in bytes.
config_sha256
class-attribute
instance-attribute
¶
config_sha256: str | None = None
The SHA256 hash of the function configuration.
dead_letter_config
class-attribute
instance-attribute
¶
dead_letter_config: DeadLetterConfig | None = None
The function's dead letter queue.
description
class-attribute
instance-attribute
¶
description: str | None = None
The function's description.
durable_config
class-attribute
instance-attribute
¶
durable_config: DurableConfig | None = None
The function's durable execution configuration settings, if the function is configured for durability.
environment
class-attribute
instance-attribute
¶
environment: EnvironmentResponse | None = None
The function's environment variables. Omitted from CloudTrail logs.
ephemeral_storage
class-attribute
instance-attribute
¶
ephemeral_storage: EphemeralStorage | None = None
The size of the function's /tmp directory in MB. The default value is
512, but can be any whole number between 512 and 10,240 MB. For more
information, see Configuring ephemeral storage
(console).
file_system_configs
class-attribute
instance-attribute
¶
file_system_configs: list[FileSystemConfig] | None = None
Connection settings for an Amazon EFS file system or an Amazon S3 Files file system.
function_arn
class-attribute
instance-attribute
¶
function_arn: str | None = None
The function's Amazon Resource Name (ARN).
function_name
class-attribute
instance-attribute
¶
function_name: str | None = None
The name of the function.
handler
class-attribute
instance-attribute
¶
handler: str | None = None
The function that Lambda calls to begin running your function.
image_config_response
class-attribute
instance-attribute
¶
image_config_response: ImageConfigResponse | None = None
The function's image configuration values.
kms_key_arn
class-attribute
instance-attribute
¶
kms_key_arn: str | None = None
The ARN of the Key Management Service (KMS) customer managed key that's used to encrypt the following resources:
-
The function's environment variables.
-
The function's Lambda SnapStart snapshots.
-
When used with
SourceKMSKeyArn, the unzipped version of the .zip deployment package that's used for function invocations. For more information, see Specifying a customer managed key for Lambda. -
The optimized version of the container image that's used for function invocations. Note that this is not the same key that's used to protect your container image in the Amazon Elastic Container Registry (Amazon ECR). For more information, see Function lifecycle.
If you don't provide a customer managed key, Lambda uses an Amazon Web Services owned key or an Amazon Web Services managed key.
last_modified
class-attribute
instance-attribute
¶
last_modified: str | None = None
The date and time that the function was last updated, in ISO-8601 format (YYYY-MM-DDThh:mm:ss.sTZD).
last_update_status
class-attribute
instance-attribute
¶
last_update_status: LastUpdateStatus | None = None
The status of the last update that was performed on the function. This
is first set to Successful after function creation completes.
last_update_status_reason
class-attribute
instance-attribute
¶
last_update_status_reason: str | None = None
The reason for the last update that was performed on the function.
last_update_status_reason_code
class-attribute
instance-attribute
¶
last_update_status_reason_code: LastUpdateStatusReasonCode | None = None
The reason code for the last update that was performed on the function.
layers
class-attribute
instance-attribute
¶
layers: list[Layer] | None = None
The function's layers.
logging_config
class-attribute
instance-attribute
¶
logging_config: LoggingConfig | None = None
The function's Amazon CloudWatch Logs configuration settings.
master_arn
class-attribute
instance-attribute
¶
master_arn: str | None = None
For Lambda@Edge functions, the ARN of the main function.
memory_size
class-attribute
instance-attribute
¶
memory_size: int | None = None
The amount of memory available to the function at runtime.
package_type
class-attribute
instance-attribute
¶
package_type: PackageType | None = None
The type of deployment package. Set to Image for container image and
set Zip for .zip file archive.
revision_id
class-attribute
instance-attribute
¶
revision_id: str | None = None
The latest updated revision of the function or alias.
runtime
class-attribute
instance-attribute
¶
runtime: Runtime | None = None
The identifier of the function's runtime. Runtime is required if the deployment package is a .zip file archive. Specifying a runtime results in an error if you're deploying a function using a container image.
The following list includes deprecated runtimes. Lambda blocks creating new functions and updating existing functions shortly after each runtime is deprecated. For more information, see Runtime use after deprecation.
For a list of all currently supported runtimes, see Supported runtimes.
runtime_version_config
class-attribute
instance-attribute
¶
runtime_version_config: RuntimeVersionConfig | None = None
The ARN of the runtime and any errors that occured.
signing_job_arn
class-attribute
instance-attribute
¶
signing_job_arn: str | None = None
The ARN of the signing job.
signing_profile_version_arn
class-attribute
instance-attribute
¶
signing_profile_version_arn: str | None = None
The ARN of the signing profile version.
snap_start
class-attribute
instance-attribute
¶
snap_start: SnapStartResponse | None = None
Set ApplyOn to PublishedVersions to create a snapshot of the
initialized execution environment when you publish a function version.
For more information, see Improving startup performance with Lambda
SnapStart.
state
class-attribute
instance-attribute
¶
state: State | None = None
The current state of the function. When the state is Inactive, you can
reactivate the function by invoking it.
state_reason
class-attribute
instance-attribute
¶
state_reason: str | None = None
The reason for the function's current state.
state_reason_code
class-attribute
instance-attribute
¶
state_reason_code: StateReasonCode | None = None
The reason code for the function's current state. When the code is
Creating, you can't invoke or modify the function.
tenancy_config
class-attribute
instance-attribute
¶
tenancy_config: TenancyConfig | None = None
The function's tenant isolation configuration settings. Determines whether the Lambda function runs on a shared or dedicated infrastructure per unique tenant.
timeout
class-attribute
instance-attribute
¶
timeout: int | None = None
The amount of time in seconds that Lambda allows a function to run before stopping it.
tracing_config
class-attribute
instance-attribute
¶
tracing_config: TracingConfigResponse | None = None
The function's X-Ray tracing configuration.
version
class-attribute
instance-attribute
¶
version: str | None = None
The version of the Lambda function.
vpc_config
class-attribute
instance-attribute
¶
vpc_config: VpcConfigResponse | None = None
The function's networking configuration.