AWS Lambda
Developer Guide

CreateFunction

Creates a new Lambda function. The function configuration is created from the request parameters, and the code for the function is provided by a .zip file. The function name is case-sensitive.

This operation requires permission for the lambda:CreateFunction action.

Request Syntax

POST /2015-03-31/functions HTTP/1.1 Content-type: application/json { "Code": { "S3Bucket": "string", "S3Key": "string", "S3ObjectVersion": "string", "ZipFile": blob }, "DeadLetterConfig": { "TargetArn": "string" }, "Description": "string", "Environment": { "Variables": { "string" : "string" } }, "FunctionName": "string", "Handler": "string", "KMSKeyArn": "string", "MemorySize": number, "Publish": boolean, "Role": "string", "Runtime": "string", "Tags": { "string" : "string" }, "Timeout": number, "TracingConfig": { "Mode": "string" }, "VpcConfig": { "SecurityGroupIds": [ "string" ], "SubnetIds": [ "string" ] } }

URI Request Parameters

The request does not use any URI parameters.

Request Body

The request accepts the following data in JSON format.

Code

The code for the function.

Type: FunctionCode object

Required: Yes

DeadLetterConfig

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.

Type: DeadLetterConfig object

Required: No

Description

A description of the function.

Type: String

Length Constraints: Minimum length of 0. Maximum length of 256.

Required: No

Environment

Environment variables that are accessible from function code during execution.

Type: Environment object

Required: No

FunctionName

The name of the lambda function.

Name formats

  • Function name - MyFunction.

  • Function ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction.

  • Partial ARN - 123456789012:function:MyFunction.

The length constraint applies only to the full ARN. If you specify only the function name, it is limited to 64 characters in length.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 140.

Pattern: (arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}(-gov)?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-_]+)(:(\$LATEST|[a-zA-Z0-9-_]+))?

Required: Yes

Handler

The name of the method within your code that Lambda calls to execute your function. For more information, see Programming Model.

Type: String

Length Constraints: Maximum length of 128.

Pattern: [^\s]+

Required: Yes

KMSKeyArn

The ARN of the KMS key used to encrypt your function's environment variables. If not provided, AWS Lambda will use a default service key.

Type: String

Pattern: (arn:(aws[a-zA-Z-]*)?:[a-z0-9-.]+:.*)|()

Required: No

MemorySize

The amount of memory that your function has access to. Increasing the function's memory also increases it's CPU allocation. The default value is 128 MB. The value must be a multiple of 64 MB.

Type: Integer

Valid Range: Minimum value of 128. Maximum value of 3008.

Required: No

Publish

Set to true to publish the first version of the function during creation.

Type: Boolean

Required: No

Role

The Amazon Resource Name (ARN) of the function's execution role.

Type: String

Pattern: arn:(aws[a-zA-Z-]*)?:iam::\d{12}:role/?[a-zA-Z_0-9+=,.@\-_/]+

Required: Yes

Runtime

The runtime version for the function.

Type: String

Valid Values: nodejs | nodejs4.3 | nodejs6.10 | nodejs8.10 | java8 | python2.7 | python3.6 | dotnetcore1.0 | dotnetcore2.0 | dotnetcore2.1 | nodejs4.3-edge | go1.x

Required: Yes

Tags

The list of tags (key-value pairs) assigned to the new function. For more information, see Tagging Lambda Functions in the AWS Lambda Developer Guide.

Type: String to string map

Required: No

Timeout

The amount of time that Lambda allows a function to run before terminating it. The default is 3 seconds. The maximum allowed value is 900 seconds.

Type: Integer

Valid Range: Minimum value of 1.

Required: No

TracingConfig

The parent object that contains your function's tracing settings.

Type: TracingConfig object

Required: No

VpcConfig

If your Lambda function accesses resources in a VPC, you provide this parameter identifying the list of security group IDs and subnet IDs. These must belong to the same VPC. You must provide at least one security group and one subnet ID.

Type: VpcConfig object

Required: No

Response Syntax

HTTP/1.1 201 Content-type: application/json { "CodeSha256": "string", "CodeSize": number, "DeadLetterConfig": { "TargetArn": "string" }, "Description": "string", "Environment": { "Error": { "ErrorCode": "string", "Message": "string" }, "Variables": { "string" : "string" } }, "FunctionArn": "string", "FunctionName": "string", "Handler": "string", "KMSKeyArn": "string", "LastModified": "string", "MasterArn": "string", "MemorySize": number, "RevisionId": "string", "Role": "string", "Runtime": "string", "Timeout": number, "TracingConfig": { "Mode": "string" }, "Version": "string", "VpcConfig": { "SecurityGroupIds": [ "string" ], "SubnetIds": [ "string" ], "VpcId": "string" } }

Response Elements

If the action is successful, the service sends back an HTTP 201 response.

The following data is returned in JSON format by the service.

CodeSha256

The SHA256 hash of the function's deployment package.

Type: String

CodeSize

The size of the function's deployment package in bytes.

Type: Long

DeadLetterConfig

The function's dead letter queue.

Type: DeadLetterConfig object

Description

The function's description.

Type: String

Length Constraints: Minimum length of 0. Maximum length of 256.

Environment

The function's environment variables.

Type: EnvironmentResponse object

FunctionArn

The function's Amazon Resource Name.

Type: String

Pattern: arn:(aws[a-zA-Z-]*)?:lambda:[a-z]{2}(-gov)?-[a-z]+-\d{1}:\d{12}:function:[a-zA-Z0-9-_\.]+(:(\$LATEST|[a-zA-Z0-9-_]+))?

FunctionName

The name of the function.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 170.

Pattern: (arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}(-gov)?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-_\.]+)(:(\$LATEST|[a-zA-Z0-9-_]+))?

Handler

The function Lambda calls to begin executing your function.

Type: String

Length Constraints: Maximum length of 128.

Pattern: [^\s]+

KMSKeyArn

The KMS key used to encrypt the function's environment variables. Only returned if you've configured a customer managed CMK.

Type: String

Pattern: (arn:(aws[a-zA-Z-]*)?:[a-z0-9-.]+:.*)|()

LastModified

The date and time that the function was last updated, in ISO-8601 format (YYYY-MM-DDThh:mm:ssTZD).

Type: String

MasterArn

The ARN of the master function.

Type: String

Pattern: arn:(aws[a-zA-Z-]*)?:lambda:[a-z]{2}(-gov)?-[a-z]+-\d{1}:\d{12}:function:[a-zA-Z0-9-_]+(:(\$LATEST|[a-zA-Z0-9-_]+))?

MemorySize

The memory allocated to the function

Type: Integer

Valid Range: Minimum value of 128. Maximum value of 3008.

RevisionId

Represents the latest updated revision of the function or alias.

Type: String

Role

The function's execution role.

Type: String

Pattern: arn:(aws[a-zA-Z-]*)?:iam::\d{12}:role/?[a-zA-Z_0-9+=,.@\-_/]+

Runtime

The runtime environment for the Lambda function.

Type: String

Valid Values: nodejs | nodejs4.3 | nodejs6.10 | nodejs8.10 | java8 | python2.7 | python3.6 | dotnetcore1.0 | dotnetcore2.0 | dotnetcore2.1 | nodejs4.3-edge | go1.x

Timeout

The amount of time that Lambda allows a function to run before terminating it.

Type: Integer

Valid Range: Minimum value of 1.

TracingConfig

The function's AWS X-Ray tracing configuration.

Type: TracingConfigResponse object

Version

The version of the Lambda function.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1024.

Pattern: (\$LATEST|[0-9]+)

VpcConfig

The function's networking configuration.

Type: VpcConfigResponse object

Errors

CodeStorageExceededException

You have exceeded your maximum total code size per account. Limits

HTTP Status Code: 400

InvalidParameterValueException

One of the parameters in the request is invalid. For example, if you provided an IAM role for AWS Lambda to assume in the CreateFunction or the UpdateFunctionConfiguration API, that AWS Lambda is unable to assume you will get this exception.

HTTP Status Code: 400

ResourceConflictException

The resource already exists.

HTTP Status Code: 409

ResourceNotFoundException

The resource (for example, a Lambda function or access policy statement) specified in the request does not exist.

HTTP Status Code: 404

ServiceException

The AWS Lambda service encountered an internal error.

HTTP Status Code: 500

TooManyRequestsException

HTTP Status Code: 429

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: