Skip to content

Latest commit

 

History

History
410 lines (337 loc) · 23.5 KB

API_CreateFunction.md

File metadata and controls

410 lines (337 loc) · 23.5 KB

CreateFunction

Creates a Lambda function. To create a function, you need a deployment package and an execution role. The deployment package contains your function code. The execution role grants the function permission to use AWS services, such as Amazon CloudWatch Logs for log streaming and AWS X-Ray for request tracing.

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

If another account or an AWS service invokes your function, use AddPermission to grant permission by creating a resource-based 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 AWS services, create an event source mapping (CreateEventSourceMapping), or configure a function trigger in the other service. For more information, see Invoking Functions.

Request Syntax

POST /2015-03-31/functions HTTP/1.1
Content-type: application/json

{
   "[Code](#SSS-CreateFunction-request-Code)": { 
      "[S3Bucket](API_FunctionCode.md#SSS-Type-FunctionCode-S3Bucket)": "string",
      "[S3Key](API_FunctionCode.md#SSS-Type-FunctionCode-S3Key)": "string",
      "[S3ObjectVersion](API_FunctionCode.md#SSS-Type-FunctionCode-S3ObjectVersion)": "string",
      "[ZipFile](API_FunctionCode.md#SSS-Type-FunctionCode-ZipFile)": blob
   },
   "[DeadLetterConfig](#SSS-CreateFunction-request-DeadLetterConfig)": { 
      "[TargetArn](API_DeadLetterConfig.md#SSS-Type-DeadLetterConfig-TargetArn)": "string"
   },
   "[Description](#SSS-CreateFunction-request-Description)": "string",
   "[Environment](#SSS-CreateFunction-request-Environment)": { 
      "[Variables](API_Environment.md#SSS-Type-Environment-Variables)": { 
         "string" : "string" 
      }
   },
   "[FileSystemConfigs](#SSS-CreateFunction-request-FileSystemConfigs)": [ 
      { 
         "[Arn](API_FileSystemConfig.md#SSS-Type-FileSystemConfig-Arn)": "string",
         "[LocalMountPath](API_FileSystemConfig.md#SSS-Type-FileSystemConfig-LocalMountPath)": "string"
      }
   ],
   "[FunctionName](#SSS-CreateFunction-request-FunctionName)": "string",
   "[Handler](#SSS-CreateFunction-request-Handler)": "string",
   "[KMSKeyArn](#SSS-CreateFunction-request-KMSKeyArn)": "string",
   "[Layers](#SSS-CreateFunction-request-Layers)": [ "string" ],
   "[MemorySize](#SSS-CreateFunction-request-MemorySize)": number,
   "[Publish](#SSS-CreateFunction-request-Publish)": boolean,
   "[Role](#SSS-CreateFunction-request-Role)": "string",
   "[Runtime](#SSS-CreateFunction-request-Runtime)": "string",
   "[Tags](#SSS-CreateFunction-request-Tags)": { 
      "string" : "string" 
   },
   "[Timeout](#SSS-CreateFunction-request-Timeout)": number,
   "[TracingConfig](#SSS-CreateFunction-request-TracingConfig)": { 
      "[Mode](API_TracingConfig.md#SSS-Type-TracingConfig-Mode)": "string"
   },
   "[VpcConfig](#SSS-CreateFunction-request-VpcConfig)": { 
      "[SecurityGroupIds](API_VpcConfig.md#SSS-Type-VpcConfig-SecurityGroupIds)": [ "string" ],
      "[SubnetIds](API_VpcConfig.md#SSS-Type-VpcConfig-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

** FileSystemConfigs ** Connection settings for an Amazon EFS file system.
Type: Array of FileSystemConfig objects
Array Members: Maximum number of 1 item.
Required: No

** FunctionName ** The name 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.
    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. The format includes the file name. It can also include namespaces and other qualifiers, depending on the runtime. For more information, see Programming Model.
Type: String
Length Constraints: Maximum length of 128.
Pattern: [^\s]+
Required: Yes

** KMSKeyArn ** The ARN of the AWS Key Management Service (AWS KMS) key that's used to encrypt your function's environment variables. If it's not provided, AWS Lambda uses a default service key.
Type: String
Pattern: (arn:(aws[a-zA-Z-]*)?:[a-z0-9-.]+:.*)|()
Required: No

** Layers ** A list of function layers to add to the function's execution environment. Specify each layer by its ARN, including the version.
Type: Array of strings
Length Constraints: Minimum length of 1. Maximum length of 140.
Pattern: arn:[a-zA-Z0-9-]+:lambda:[a-zA-Z0-9-]+:\d{12}:layer:[a-zA-Z0-9-_]+:[0-9]+
Required: No

** MemorySize ** The amount of memory that your function has access to. Increasing the function's memory also increases its 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 identifier of the function's runtime.
Type: String
Valid Values: nodejs10.x | nodejs12.x | java8 | java11 | python2.7 | python3.6 | python3.7 | python3.8 | dotnetcore2.1 | dotnetcore3.1 | go1.x | ruby2.5 | ruby2.7 | provided
Required: Yes

** Tags ** A list of tags to apply to the function.
Type: String to string map
Required: No

** Timeout ** The amount of time that Lambda allows a function to run before stopping it. The default is 3 seconds. The maximum allowed value is 900 seconds.
Type: Integer
Valid Range: Minimum value of 1.
Required: No

** TracingConfig ** Set Mode to Active to sample and trace a subset of incoming requests with AWS X-Ray.
Type: TracingConfig object
Required: No

** VpcConfig ** For network connectivity to AWS 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 only access resources and the internet through that VPC. For more information, see VPC Settings.
Type: VpcConfig object
Required: No

Response Syntax

HTTP/1.1 201
Content-type: application/json

{
   "[CodeSha256](#SSS-CreateFunction-response-CodeSha256)": "string",
   "[CodeSize](#SSS-CreateFunction-response-CodeSize)": number,
   "[DeadLetterConfig](#SSS-CreateFunction-response-DeadLetterConfig)": { 
      "[TargetArn](API_DeadLetterConfig.md#SSS-Type-DeadLetterConfig-TargetArn)": "string"
   },
   "[Description](#SSS-CreateFunction-response-Description)": "string",
   "[Environment](#SSS-CreateFunction-response-Environment)": { 
      "[Error](API_EnvironmentResponse.md#SSS-Type-EnvironmentResponse-Error)": { 
         "[ErrorCode](API_EnvironmentError.md#SSS-Type-EnvironmentError-ErrorCode)": "string",
         "[Message](API_EnvironmentError.md#SSS-Type-EnvironmentError-Message)": "string"
      },
      "[Variables](API_EnvironmentResponse.md#SSS-Type-EnvironmentResponse-Variables)": { 
         "string" : "string" 
      }
   },
   "[FileSystemConfigs](#SSS-CreateFunction-response-FileSystemConfigs)": [ 
      { 
         "[Arn](API_FileSystemConfig.md#SSS-Type-FileSystemConfig-Arn)": "string",
         "[LocalMountPath](API_FileSystemConfig.md#SSS-Type-FileSystemConfig-LocalMountPath)": "string"
      }
   ],
   "[FunctionArn](#SSS-CreateFunction-response-FunctionArn)": "string",
   "[FunctionName](#SSS-CreateFunction-response-FunctionName)": "string",
   "[Handler](#SSS-CreateFunction-response-Handler)": "string",
   "[KMSKeyArn](#SSS-CreateFunction-response-KMSKeyArn)": "string",
   "[LastModified](#SSS-CreateFunction-response-LastModified)": "string",
   "[LastUpdateStatus](#SSS-CreateFunction-response-LastUpdateStatus)": "string",
   "[LastUpdateStatusReason](#SSS-CreateFunction-response-LastUpdateStatusReason)": "string",
   "[LastUpdateStatusReasonCode](#SSS-CreateFunction-response-LastUpdateStatusReasonCode)": "string",
   "[Layers](#SSS-CreateFunction-response-Layers)": [ 
      { 
         "[Arn](API_Layer.md#SSS-Type-Layer-Arn)": "string",
         "[CodeSize](API_Layer.md#SSS-Type-Layer-CodeSize)": number
      }
   ],
   "[MasterArn](#SSS-CreateFunction-response-MasterArn)": "string",
   "[MemorySize](#SSS-CreateFunction-response-MemorySize)": number,
   "[RevisionId](#SSS-CreateFunction-response-RevisionId)": "string",
   "[Role](#SSS-CreateFunction-response-Role)": "string",
   "[Runtime](#SSS-CreateFunction-response-Runtime)": "string",
   "[State](#SSS-CreateFunction-response-State)": "string",
   "[StateReason](#SSS-CreateFunction-response-StateReason)": "string",
   "[StateReasonCode](#SSS-CreateFunction-response-StateReasonCode)": "string",
   "[Timeout](#SSS-CreateFunction-response-Timeout)": number,
   "[TracingConfig](#SSS-CreateFunction-response-TracingConfig)": { 
      "[Mode](API_TracingConfigResponse.md#SSS-Type-TracingConfigResponse-Mode)": "string"
   },
   "[Version](#SSS-CreateFunction-response-Version)": "string",
   "[VpcConfig](#SSS-CreateFunction-response-VpcConfig)": { 
      "[SecurityGroupIds](API_VpcConfigResponse.md#SSS-Type-VpcConfigResponse-SecurityGroupIds)": [ "string" ],
      "[SubnetIds](API_VpcConfigResponse.md#SSS-Type-VpcConfigResponse-SubnetIds)": [ "string" ],
      "[VpcId](API_VpcConfigResponse.md#SSS-Type-VpcConfigResponse-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

** FileSystemConfigs ** Connection settings for an Amazon EFS file system.
Type: Array of FileSystemConfig objects
Array Members: Maximum number of 1 item.

** FunctionArn ** The function's Amazon Resource Name (ARN).
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 that Lambda calls to begin executing your function.
Type: String
Length Constraints: Maximum length of 128.
Pattern: [^\s]+

** KMSKeyArn ** The KMS key that's used to encrypt the function's environment variables. This key is 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:ss.sTZD).
Type: String

** LastUpdateStatus ** The status of the last update that was performed on the function. This is first set to Successful after function creation completes.
Type: String
Valid Values: Successful | Failed | InProgress

** LastUpdateStatusReason ** The reason for the last update that was performed on the function.
Type: String

** LastUpdateStatusReasonCode ** The reason code for the last update that was performed on the function.
Type: String
Valid Values: EniLimitExceeded | InsufficientRolePermissions | InvalidConfiguration | InternalError | SubnetOutOfIPAddresses | InvalidSubnet | InvalidSecurityGroup

** Layers ** The function's layers.
Type: Array of Layer objects

** MasterArn ** For Lambda@Edge functions, 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 that's allocated to the function.
Type: Integer
Valid Range: Minimum value of 128. Maximum value of 3008.

** RevisionId ** 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: nodejs10.x | nodejs12.x | java8 | java11 | python2.7 | python3.6 | python3.7 | python3.8 | dotnetcore2.1 | dotnetcore3.1 | go1.x | ruby2.5 | ruby2.7 | provided

** State ** The current state of the function. When the state is Inactive, you can reactivate the function by invoking it.
Type: String
Valid Values: Pending | Active | Inactive | Failed

** StateReason ** The reason for the function's current state.
Type: String

** StateReasonCode ** The reason code for the function's current state. When the code is Creating, you can't invoke or modify the function.
Type: String
Valid Values: Idle | Creating | Restoring | EniLimitExceeded | InsufficientRolePermissions | InvalidConfiguration | InternalError | SubnetOutOfIPAddresses | InvalidSubnet | InvalidSecurityGroup

** Timeout ** The amount of time in seconds that Lambda allows a function to run before stopping 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. Learn more
HTTP Status Code: 400

InvalidParameterValueException
One of the parameters in the request is invalid.
HTTP Status Code: 400

ResourceConflictException
The resource already exists, or another operation is in progress.
HTTP Status Code: 409

ResourceNotFoundException
The resource 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
The request throughput limit was exceeded.
HTTP Status Code: 429

See Also

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