You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc_source/applications-tutorial.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ When the deployment process completes, invoke the function from the Lambda conso
94
94
95
95
1. Choose **Test**\.
96
96
97
-
The Lambda console executes your function and displays the result\. Expand the **Details** section under the result to see the output and execution details\.
97
+
The Lambda console runs your function and displays the result\. Expand the **Details** section under the result to see the output and execution details\.
Copy file name to clipboardExpand all lines: doc_source/applications-usecases.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ The diagram illustrates the following sequence:
24
24
25
25
1. Amazon S3 invokes your Lambda function using the permissions provided by the [execution role](lambda-intro-execution-role.md)\.
26
26
27
-
1. AWS Lambda executes the Lambda function, specifying the event as a parameter\.
27
+
1. AWS Lambda runs the Lambda function, specifying the event as a parameter\.
28
28
29
29
You configure Amazon S3 to invoke your function as a bucket notification action\. To grant Amazon S3 permission to invoke the function, update the function's [resource\-based policy](access-control-resource-based.md)\.
Copy file name to clipboardExpand all lines: doc_source/best-practices.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -16,23 +16,23 @@ The following are recommended best practices for using AWS Lambda:
16
16
var foo = event.foo;
17
17
var bar = event.bar;
18
18
var result = MyLambdaFunction (foo, bar);
19
-
19
+
20
20
callback(null, result);
21
21
}
22
-
22
+
23
23
function MyLambdaFunction (foo, bar) {
24
24
// MyLambdaFunction logic here
25
25
}
26
26
```
27
27
+**Take advantage of execution context reuse to improve the performance of your function\.** Initialize SDK clients and database connections outside of the function handler, and cache static assets locally in the `/tmp` directory\. Subsequent invocations processed by the same instance of your function can reuse these resources\. This saves execution time and cost\.
28
28
29
-
To avoid potential data leaks across invocations, don’t use the execution context to store user data, events, or other information with security implications\. If your function relies on a mutable state that can’t be stored in memory within the handler, consider creating a separate function or separate versions of a function for each user\.
29
+
To avoid potential data leaks across invocations, don’t use the execution environment to store user data, events, or other information with security implications\. If your function relies on a mutable state that can’t be stored in memory within the handler, consider creating a separate function or separate versions of a function for each user\.
30
30
+**Use a keep\-alive directive to maintain persistent connections\.** Lambda purges idle connections over time\. Attempting to reuse an idle connection when invoking a function will result in a connection error\. To maintain your persistent connection, use the keep\-alive directive associated with your runtime\. For an example, see [Reusing Connections with Keep\-Alive in Node\.js](https://docs.amazonaws.cn/en_us/sdk-for-javascript/v2/developer-guide/node-reusing-connections.html)\.
31
31
+**Use [environment variables](configuration-envvars.md) to pass operational parameters to your function\.** For example, if you are writing to an Amazon S3 bucket, instead of hard\-coding the bucket name you are writing to, configure the bucket name as an environment variable\.
32
32
+**Control the dependencies in your function's deployment package\.** The AWS Lambda execution environment contains a number of libraries such as the AWS SDK for the Node\.js and Python runtimes \(a full list can be found here: [AWS Lambda runtimes](lambda-runtimes.md)\)\. To enable the latest set of features and security updates, Lambda will periodically update these libraries\. These updates may introduce subtle changes to the behavior of your Lambda function\. To have full control of the dependencies your function uses, package all of your dependencies with your deployment package\.
33
33
+**Minimize your deployment package size to its runtime necessities\.** This will reduce the amount of time that it takes for your deployment package to be downloaded and unpacked ahead of invocation\. For functions authored in Java or \.NET Core, avoid uploading the entire AWS SDK library as part of your deployment package\. Instead, selectively depend on the modules which pick up components of the SDK you need \(e\.g\. DynamoDB, Amazon S3 SDK modules and [Lambda core libraries](https://github.com/aws/aws-lambda-java-libs)\)\.
34
34
+**Reduce the time it takes Lambda to unpack deployment packages** authored in Java by putting your dependency `.jar` files in a separate /lib directory\. This is faster than putting all your function’s code in a single jar with a large number of `.class` files\. See [AWS Lambda deployment package in Java](java-package.md) for instructions\.
35
-
+**Minimize the complexity of your dependencies\.** Prefer simpler frameworks that load quickly on [execution context](runtimes-context.md) startup\. For example, prefer simpler Java dependency injection \(IoC\) frameworks like [Dagger](https://google.github.io/dagger/) or [Guice](https://github.com/google/guice), over more complex ones like [Spring Framework](https://github.com/spring-projects/spring-framework)\.
35
+
+**Minimize the complexity of your dependencies\.** Prefer simpler frameworks that load quickly on [execution environment](runtimes-context.md) startup\. For example, prefer simpler Java dependency injection \(IoC\) frameworks like [Dagger](https://google.github.io/dagger/) or [Guice](https://github.com/google/guice), over more complex ones like [Spring Framework](https://github.com/spring-projects/spring-framework)\.
36
36
+**Avoid using recursive code** in your Lambda function, wherein the function automatically calls itself until some arbitrary criteria is met\. This could lead to unintended volume of function invocations and escalated costs\. If you do accidentally do so, set the function concurrent execution limit to `0` immediately to throttle all invocations to the function, while you update the code\.
37
37
38
38
## Function configuration<aname="function-configuration"></a>
Copy file name to clipboardExpand all lines: doc_source/configuration-console.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -15,13 +15,13 @@ With the function node selected in the designer, you can modify the following se
15
15
16
16
**Function settings**
17
17
+**Code** – The code and dependencies of your function\. For scripting languages, you can edit your function code in the embedded [editor](code-editor.md)\. To add libraries, or for languages that the editor doesn't support, upload a [deployment package](gettingstarted-features.md#gettingstarted-features-package)\. If your deployment package is larger than 50 MB, choose **Upload a file from Amazon S3**\.
18
-
+**Runtime** – The [Lambda runtime](lambda-runtimes.md) that executes your function\.
19
-
+**Handler** – The method that the runtime executes when your function is invoked, such as `index.handler`\. The first value is the name of the file or module\. The second value is the name of the method\.
18
+
+**Runtime** – The [Lambda runtime](lambda-runtimes.md) that runs your function\.
19
+
+**Handler** – The method that the runtime runs when your function is invoked, such as `index.handler`\. The first value is the name of the file or module\. The second value is the name of the method\.
20
20
+**Environment variables** – Key\-value pairs that Lambda sets in the execution environment\.[ Use environment variables](configuration-envvars.md) to extend your function's configuration outside of code\.
21
21
+**Tags** – Key\-value pairs that Lambda attaches to your function resource\.[Use tags](configuration-tags.md) to organize Lambda functions into groups for cost reporting and filtering in the Lambda console\.
22
22
23
23
Tags apply to the entire function, including all versions and aliases\.
24
-
+**Execution role** – The [IAM role](lambda-intro-execution-role.md) that AWS Lambda assumes when it executes your function\.
24
+
+**Execution role** – The [IAM role](lambda-intro-execution-role.md) that AWS Lambda assumes when it runs your function\.
25
25
+**Description** – A description of the function\.
26
26
+**Memory**– The amount of memory available to the function during execution\. Choose an amount [between 128 MB and 3,008 MB](gettingstarted-limits.md) in 64\-MB increments\.
Copy file name to clipboardExpand all lines: doc_source/configuration-envvars.md
+9-2
Original file line number
Diff line number
Diff line change
@@ -27,10 +27,17 @@ You set environment variables on the unpublished version of your function by spe
27
27
28
28
1. Choose **Save**\.
29
29
30
-
Use environment variables to pass environment\-specific settings to your code\. For example, you can have two functions with the same code but different configuration\. One function connects to a test database, and the other connects to a production database\. In this situation, you use environment variables to tell the function the hostname and other connection details for the database\. You might also set an environment variable to configure your test environment to use more verbose logging or more detailed tracing\.
30
+
Use environment variables to pass environment\-specific settings to your code\. For example, you can have two functions with the same code but different configuration\. One function connects to a test database, and the other connects to a production database\. In this situation, you use environment variables to tell the function the hostname and other connection details for the database\.
31
+
32
+
The following example shows how to define the database host and database name as environment variables\.
If you want your test environment to generate more debug information than the production environment, you could set an environment variable to configure your test environment to use more verbose logging or more detailed tracing\.
37
+
38
+
**Note**
39
+
Environment variables are not evaluated prior to the function invocation\. Any value you define is considered a literal string and not expanded\. Perform the variable evaluation in the function code\.
40
+
34
41
To retrieve environment variables in your function code, use the standard method for your programming language\.
35
42
36
43
------
@@ -99,6 +106,7 @@ Lambda [runtimes](lambda-runtimes.md) set several environment variables during i
99
106
100
107
**Reserved environment variables**
101
108
+`_HANDLER` – The handler location configured on the function\.
109
+
+`_X_AMZN_TRACE_ID` – The [X\-Ray tracing header](services-xray.md)\.
102
110
+`AWS_REGION` – The AWS Region where the Lambda function is executed\.
103
111
+`AWS_EXECUTION_ENV` – The [runtime identifier](lambda-runtimes.md), prefixed by `AWS_Lambda_`—for example, `AWS_Lambda_java8`\.
104
112
+`AWS_LAMBDA_FUNCTION_NAME` – The name of the function\.
@@ -120,7 +128,6 @@ The following additional environment variables aren't reserved and can be extend
120
128
+`NODE_PATH` – \([Node\.js](lambda-nodejs.md)\) The Node\.js library path \(`/opt/nodejs/node12/node_modules/:/opt/nodejs/node_modules:$LAMBDA_RUNTIME_DIR/node_modules`\)\.
Copy file name to clipboardExpand all lines: doc_source/configuration-vpc.md
+46-22
Original file line number
Diff line number
Diff line change
@@ -2,22 +2,6 @@
2
2
3
3
You can configure a Lambda function to connect to private subnets in a virtual private cloud \(VPC\) in your AWS account\. Use Amazon Virtual Private Cloud \(Amazon VPC\) to create a private network for resources such as databases, cache instances, or internal services\. Connect your function to the VPC to access private resources during execution\.
4
4
5
-
**To connect a function to a VPC**
6
-
7
-
1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\.
8
-
9
-
1. Choose a function\.
10
-
11
-
1. Under **VPC**, choose **Edit**\.
12
-
13
-
1. For **VPC connection**, choose **Custom VPC**\.
14
-
15
-
1. Choose a VPC, subnets, and security groups\.
16
-
**Note**
17
-
Connect your function to private subnets to access private resources\. If your function needs internet access, use [network address translation \(NAT\)](#vpc-internet)\. Connecting a function to a public subnet doesn't give it internet access or a public IP address\.
18
-
19
-
1. Choose **Save**\.
20
-
21
5
When you connect a function to a VPC, Lambda creates an [elastic network interface](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_ElasticNetworkInterfaces.html) for each combination of security group and subnet in your function's VPC configuration\. This process can take about a minute\.
22
6
23
7
While Lambda creates a network interface, you can't perform additional operations that target the function, such as [creating versions](configuration-versions.md) or updating the function's code\. For new functions, you can't invoke the function until its state changes from `Pending` to `Active`\. For existing functions, you can still invoke an earlier version while the update is in progress\. For more information about function states, see [Monitoring the state of a function with the Lambda API](functions-states.md)\.
@@ -28,15 +12,13 @@ If your functions aren't active for a long period of time, Lambda reclaims its n
28
12
29
13
Lambda functions can't connect directly to a VPC with [ dedicated instance tenancy](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/dedicated-instance.html)\. To connect to resources in a dedicated VPC, [peer it to a second VPC with default tenancy](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-dedicated-vpc/)\.
30
14
31
-
**VPC tutorials**
32
-
+[Tutorial: Configuring a Lambda function to access Amazon RDS in an Amazon VPC](services-rds-tutorial.md)
33
-
+[Tutorial: Configuring a Lambda function to access Amazon ElastiCache in an Amazon VPC](services-elasticache-tutorial.md)
34
-
35
15
**Topics**
36
16
+[Execution role and user permissions](#vpc-permissions)
37
-
+[Configuring VPC access with the Lambda API](#vpc-configuring)
17
+
+[Configuring VPC access with the Lambda console](#vpc-configuring)
18
+
+[Configuring VPC access with the Lambda API](#vpc-configuring-api)
38
19
+[Using IAM condition keys for VPC settings](#vpc-conditions)
39
20
+[Internet and service access for VPC\-connected functions](#vpc-internet)
21
+
+[VPC tutorials](#vpc-tutorials)
40
22
+[Sample VPC configurations](#vpc-samples)
41
23
42
24
## Execution role and user permissions<aname="vpc-permissions"></a>
@@ -57,7 +39,43 @@ When you configure VPC connectivity, Lambda uses your permissions to verify netw
57
39
+**ec2:DescribeSubnets**
58
40
+**ec2:DescribeVpcs**
59
41
60
-
## Configuring VPC access with the Lambda API<aname="vpc-configuring"></a>
42
+
## Configuring VPC access with the Lambda console<aname="vpc-configuring"></a>
43
+
44
+
If your [IAM permissions](#vpc-conditions) allow you only to create Lambda functions that connect to your VPC, you must configure the VPC when you create the function\. If your IAM permissions allow you to create functions that aren't connected to your VPC, you can add the VPC configuration after you create the function\.
45
+
46
+
**To configure a VPC when you create a function**
47
+
48
+
1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\.
49
+
50
+
1. Choose **Create function**\.
51
+
52
+
1. Under **Basic information**, for **Function name**, enter a name for your function\.
53
+
54
+
1. Expand **Advanced settings**\.
55
+
56
+
1. Under **Network**, choose a **VPC** for your function to access\.
57
+
58
+
1. Choose subnets and security groups\. When you choose a security group, the console displays the inbound and outbound rules for that security group\.
59
+
**Note**
60
+
To access private resources, connect your function to private subnets\. If your function needs internet access, use [network address translation \(NAT\)](#vpc-internet)\. Connecting a function to a public subnet doesn't give it internet access or a public IP address\.
61
+
62
+
1. Choose **Create function**\.
63
+
64
+
**To configure a VPC for an existing function**
65
+
66
+
1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\.
67
+
68
+
1. Choose a function\.
69
+
70
+
1. Under **VPC**, choose **Edit**\.
71
+
72
+
1. Choose a VPC, subnets, and security groups\.
73
+
**Note**
74
+
To access private resources, connect your function to private subnets\. If your function needs internet access, use [network address translation \(NAT\)](#vpc-internet)\. Connecting a function to a public subnet doesn't give it internet access or a public IP address\.
75
+
76
+
1. Choose **Save**\.
77
+
78
+
## Configuring VPC access with the Lambda API<aname="vpc-configuring-api"></a>
61
79
62
80
To connect a Lambda function to a VPC, you can use the following API operations:
63
81
+[CreateFunction](API_CreateFunction.md)
@@ -269,6 +287,12 @@ Several AWS services offer [VPC endpoints](https://docs.aws.amazon.com/vpc/lates
269
287
270
288
Internet access from a private subnet requires network address translation \(NAT\)\. To give your function access to the internet, route outbound traffic to a [NAT gateway](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html) in a public subnet\. The NAT gateway has a public IP address and can connect to the internet through the VPC's internet gateway\. For more information, see [How do I give internet access to my Lambda function in a VPC?](https://aws.amazon.com/premiumsupport/knowledge-center/internet-access-lambda-function/)
271
289
290
+
## VPC tutorials<aname="vpc-tutorials"></a>
291
+
292
+
In the following tutorials, you connect a Lambda function to resources in your VPC\.
293
+
+[Tutorial: Configuring a Lambda function to access Amazon RDS in an Amazon VPC](services-rds-tutorial.md)
294
+
+[Tutorial: Configuring a Lambda function to access Amazon ElastiCache in an Amazon VPC](services-elasticache-tutorial.md)
You can use the following sample AWS CloudFormation templates to create VPC configurations to use with Lambda functions\. There are two templates available in this guide's GitHub repository:
0 commit comments