id
stringlengths
14
16
text
stringlengths
1
2.43k
source
stringlengths
99
229
14b5e3381c3e-1
When you use an [event source mapping](invocation-eventsourcemapping.md) to invoke your function, Lambda uses the execution role to read event data\. For example, an event source mapping for Amazon Kinesis reads events from a data stream and sends them to your function in batches\. You can use event source mappings with the following services: **Services that Lambda reads events from** + [Amazon DynamoDB](with-ddb.md) + [Amazon Kinesis](with-kinesis.md) + [Amazon Managed Streaming for Apache Kafka](with-msk.md) + [Amazon Simple Queue Service](with-sqs.md) In addition to the managed policies, the Lambda console provides templates for creating a custom policy that has the permissions related to additional use cases\. When you create a function in the Lambda console, you can choose to create a new execution role with permissions from one or more templates\. These templates are also applied automatically when you create a function from a blueprint, or when you configure options that require access to other services\. Example templates are available in this guide's [GitHub repository](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/iam-policies)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-intro-execution-role.md
a826a823010b-0
In this tutorial, you create a simple Android mobile application that uses Amazon Cognito to get credentials and invokes a Lambda function\. ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/lambda-android.png) The mobile application retrieves AWS credentials from an Amazon Cognito identity pool and uses them to invoke a Lambda function with an event that contains request data\. The function processes the request and returns a response to the front\-end\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
83ab5ff31bd8-0
This tutorial assumes that you have some knowledge of basic Lambda operations and the Lambda console\. If you haven't already, follow the instructions in [Getting started with AWS Lambda](getting-started.md) to create your first Lambda function\. To follow the procedures in this guide, you will need a command line terminal or shell to run commands\. Commands are shown in listings preceded by a prompt symbol \($\) and the name of the current directory, when appropriate: ``` ~/lambda-project$ this is a command this is output ``` For long commands, an escape character \(`\`\) is used to split a command over multiple lines\. On Linux and macOS, use your preferred shell and package manager\. On Windows 10, you can [install the Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows\-integrated version of Ubuntu and Bash\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
5e51061e8507-0
Create the [execution role](lambda-intro-execution-role.md) that gives your function permission to access AWS resources\. **To create an execution role** 1. Open the [roles page](https://console.aws.amazon.com/iam/home#/roles) in the IAM console\. 1. Choose **Create role**\. 1. Create a role with the following properties\. + **Trusted entity** – **AWS Lambda**\. + **Permissions** – **AWSLambdaBasicExecutionRole**\. + **Role name** – **lambda\-android\-role**\. The **AWSLambdaBasicExecutionRole** policy has the permissions that the function needs to write logs to CloudWatch Logs\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
4cb5b72d25e7-0
The following example uses data to generate a string response\. **Note** For sample code in other languages, see [Sample function code](with-android-create-package.md)\. **Example index\.js** ``` exports.handler = function(event, context, callback) { console.log("Received event: ", event); var data = { "greetings": "Hello, " + event.firstName + " " + event.lastName + "." }; callback(null, data); } ``` **To create the function** 1. Copy the sample code into a file named `index.js`\. 1. Create a deployment package\. ``` $ zip function.zip index.js ``` 1. Create a Lambda function with the `create-function` command\. ``` $ aws lambda create-function --function-name AndroidBackendLambdaFunction \ --zip-file fileb://function.zip --handler index.handler --runtime nodejs12.x \ --role arn:aws:iam::123456789012:role/lambda-android-role ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
ac5b9e4b7780-0
Invoke the function manually using the sample event data\. **To test the Lambda function \(AWS CLI\)** 1. Save the following sample event JSON in a file, `input.txt`\. ``` { "firstName": "first-name", "lastName": "last-name" } ``` 1. Execute the following `invoke` command: ``` $ aws lambda invoke --function-name AndroidBackendLambdaFunction \ --payload file://file-path/input.txt outputfile.txt ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
ee45d059aa4f-0
In this section, you create an Amazon Cognito identity pool\. The identity pool has two IAM roles\. You update the IAM role for unauthenticated users and grant permissions to execute the `AndroidBackendLambdaFunction` Lambda function\. For more information about IAM roles, see [IAM roles](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html) in the *IAM User Guide*\. For more information about Amazon Cognito services, see the [Amazon Cognito](https://aws.amazon.com/cognito/) product detail page\. **To create an identity pool** 1. Open the [Amazon Cognito console](https://console.aws.amazon.com/cognito)\. 1. Create a new identity pool called `JavaFunctionAndroidEventHandlerPool`\. Before you follow the procedure to create an identity pool, note the following: + The identity pool you are creating must allow access to unauthenticated identities because our example mobile application does not require a user log in\. Therefore, make sure to select the **Enable access to unauthenticated identities** option\. + Add the following statement to the permission policy associated with the unauthenticated identities\. ``` { "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], "Resource": [
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
ee45d059aa4f-1
"Action": [ "lambda:InvokeFunction" ], "Resource": [ "arn:aws:lambda:us-east-1:123456789012:function:AndroidBackendLambdaFunction" ] } ``` The resulting policy will be as follows: ``` { "Version":"2012-10-17", "Statement":[ { "Effect":"Allow", "Action":[ "mobileanalytics:PutEvents", "cognito-sync:*" ], "Resource":[ "*" ] }, { "Effect":"Allow", "Action":[ "lambda:invokefunction" ], "Resource":[ "arn:aws:lambda:us-east-1:account-id:function:AndroidBackendLambdaFunction" ] } ] } ``` For instructions about how to create an identity pool, log in to the [Amazon Cognito console](https://console.aws.amazon.com/cognito/home) and follow the **New Identity Pool** wizard\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
ee45d059aa4f-2
1. Note the identity pool ID\. You specify this ID in your mobile application you create in the next section\. The app uses this ID when it sends request to Amazon Cognito to request for temporary security credentials\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
67328f1a660d-0
Create a simple Android mobile application that generates events and invokes Lambda functions by passing the event data as parameters\. The following instructions have been verified using Android studio\. 1. Create a new Android project called `AndroidEventGenerator` using the following configuration: + Select the **Phone and Tablet** platform\. + Choose **Blank Activity**\. 1. In the build\.gradle \(`Module:app`\) file, add the following in the `dependencies` section: ``` compile 'com.amazonaws:aws-android-sdk-core:2.2.+' compile 'com.amazonaws:aws-android-sdk-lambda:2.2.+' ``` 1. Build the project so that the required dependencies are downloaded, as needed\. 1. In the Android application manifest \(`AndroidManifest.xml`\), add the following permissions so that your application can connect to the Internet\. You can add them just before the `</manifest>` end tag\. ``` <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> ``` 1. In `MainActivity`, add the following imports: ``` import com.amazonaws.mobileconnectors.lambdainvoker.*;
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
67328f1a660d-1
``` import com.amazonaws.mobileconnectors.lambdainvoker.*; import com.amazonaws.auth.CognitoCachingCredentialsProvider; import com.amazonaws.regions.Regions; ``` 1. In the `package` section, add the following two classes \(`RequestClass` and `ResponseClass`\)\. Note that the POJO is same as the POJO you created in your Lambda function in the preceding section\. + `RequestClass`\. The instances of this class act as the POJO \(Plain Old Java Object\) for event data which consists of first and last name\. If you are using Java example for your Lambda function you created in the preceding section, this POJO is same as the POJO you created in your Lambda function code\. ``` package com.example....lambdaeventgenerator; public class RequestClass { String firstName; String lastName; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public RequestClass(String firstName, String lastName) {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
67328f1a660d-2
this.lastName = lastName; } public RequestClass(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } public RequestClass() { } } ``` + `ResponseClass` ``` package com.example....lambdaeventgenerator; public class ResponseClass { String greetings; public String getGreetings() { return greetings; } public void setGreetings(String greetings) { this.greetings = greetings; } public ResponseClass(String greetings) { this.greetings = greetings; } public ResponseClass() { } } ``` 1. In the same package, create interface called `MyInterface` for invoking the `AndroidBackendLambdaFunction` Lambda function\. ``` package com.example.....lambdaeventgenerator; import com.amazonaws.mobileconnectors.lambdainvoker.LambdaFunction; public interface MyInterface { /** * Invoke the Lambda function "AndroidBackendLambdaFunction". * The function name is the method name.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
67328f1a660d-3
/** * Invoke the Lambda function "AndroidBackendLambdaFunction". * The function name is the method name. */ @LambdaFunction ResponseClass AndroidBackendLambdaFunction(RequestClass request); } ``` The `@LambdaFunction` annotation in the code maps the specific client method to the same\-name Lambda function\. 1. To keep the application simple, we are going to add code to invoke the Lambda function in the `onCreate()` event handler\. In `MainActivity`, add the following code toward the end of the `onCreate()` code\. ``` // Create an instance of CognitoCachingCredentialsProvider CognitoCachingCredentialsProvider cognitoProvider = new CognitoCachingCredentialsProvider( this.getApplicationContext(), "identity-pool-id", Regions.US_WEST_2); // Create LambdaInvokerFactory, to be used to instantiate the Lambda proxy. LambdaInvokerFactory factory = new LambdaInvokerFactory(this.getApplicationContext(), Regions.US_WEST_2, cognitoProvider); // Create the Lambda proxy object with a default Json data binder. // You can provide your own data binder by implementing // LambdaDataBinder.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
67328f1a660d-4
// You can provide your own data binder by implementing // LambdaDataBinder. final MyInterface myInterface = factory.build(MyInterface.class); RequestClass request = new RequestClass("John", "Doe"); // The Lambda function invocation results in a network call. // Make sure it is not called from the main thread. new AsyncTask<RequestClass, Void, ResponseClass>() { @Override protected ResponseClass doInBackground(RequestClass... params) { // invoke "echo" method. In case it fails, it will throw a // LambdaFunctionException. try { return myInterface.AndroidBackendLambdaFunction(params[0]); } catch (LambdaFunctionException lfe) { Log.e("Tag", "Failed to invoke echo", lfe); return null; } } @Override protected void onPostExecute(ResponseClass result) { if (result == null) { return; } // Do a toast Toast.makeText(MainActivity.this, result.getGreetings(), Toast.LENGTH_LONG).show(); } }.execute(request); ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
67328f1a660d-5
} }.execute(request); ``` 1. Run the code and verify it as follows: + The `Toast.makeText()` displays the response returned\. + Verify that CloudWatch Logs shows the log created by the Lambda function\. It should show the event data \(first name and last name\)\. You can also verify this in the AWS Lambda console\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-android-example.md
0c41618ec6d1-0
In this tutorial, you create a Lambda function with a custom runtime\. You start by including the runtime in the function's deployment package\. Then you migrate it to a layer that you manage independently from the function\. Finally, you share the runtime layer with the world by updating its resource\-based permissions policy\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
273a156bdfaa-0
This tutorial assumes that you have some knowledge of basic Lambda operations and the Lambda console\. If you haven't already, follow the instructions in [Getting started with AWS Lambda](getting-started.md) to create your first Lambda function\. To follow the procedures in this guide, you will need a command line terminal or shell to run commands\. Commands are shown in listings preceded by a prompt symbol \($\) and the name of the current directory, when appropriate: ``` ~/lambda-project$ this is a command this is output ``` For long commands, an escape character \(`\`\) is used to split a command over multiple lines\. On Linux and macOS, use your preferred shell and package manager\. On Windows 10, you can [install the Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows\-integrated version of Ubuntu and Bash\. You need an IAM role to create a Lambda function\. The role needs permission to send logs to CloudWatch Logs and access the AWS services that your function uses\. If you don't have a role for function development, create one now\. **To create an execution role** 1. Open the [roles page](https://console.aws.amazon.com/iam/home#/roles) in the IAM console\. 1. Choose **Create role**\. 1. Create a role with the following properties\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
273a156bdfaa-1
1. Choose **Create role**\. 1. Create a role with the following properties\. + **Trusted entity** – **Lambda**\. + **Permissions** – **AWSLambdaBasicExecutionRole**\. + **Role name** – **lambda\-role**\. The **AWSLambdaBasicExecutionRole** policy has the permissions that the function needs to write logs to CloudWatch Logs\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
bff5d5ba4588-0
Create a Lambda function with a custom runtime\. This example includes two files, a runtime `bootstrap` file, and a function handler\. Both are implemented in Bash\. The runtime loads a function script from the deployment package\. It uses two variables to locate the script\. `LAMBDA_TASK_ROOT` tells it where the package was extracted, and `_HANDLER` includes the name of the script\. **Example bootstrap** ``` #!/bin/sh set -euo pipefail
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
eebd4e98c8ff-0
source $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f1).sh"
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
7697fa390a7b-0
while true do HEADERS="$(mktemp)"
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
f620864fd0e6-0
EVENT_DATA=$(curl -sS -LD "$HEADERS" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next")
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
cd62df873ec1-0
REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
9800c95a2ba8-0
RESPONSE=$($(echo "$_HANDLER" | cut -d. -f2) "$EVENT_DATA")
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
4cd6ba7983f7-0
curl -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/$REQUEST_ID/response" -d "$RESPONSE" done ``` After loading the script, the runtime processes events in a loop\. It uses the runtime API to retrieve an invocation event from Lambda, passes the event to the handler, and posts the response back to Lambda\. To get the request ID, the runtime saves the headers from the API response to a temporary file, and reads the `Lambda-Runtime-Aws-Request-Id` header from the file\. **Note** Runtimes have additional responsibilities, including error handling, and providing context information to the handler\. For details, see [Building a custom runtime](runtimes-custom.md#runtimes-custom-build)\. The script defines a handler function that takes event data, logs it to `stderr`, and returns it\. **Example function\.sh** ``` function handler () { EVENT_DATA=$1 echo "$EVENT_DATA" 1>&2; RESPONSE="Echoing request: '$EVENT_DATA'" echo $RESPONSE } ``` Save both files in a project directory named `runtime-tutorial`\. ``` runtime-tutorial β”œ bootstrap β”” function.sh ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
4cd6ba7983f7-1
``` runtime-tutorial β”œ bootstrap β”” function.sh ``` Make the files executable and add them to a ZIP archive\. ``` runtime-tutorial$ chmod 755 function.sh bootstrap runtime-tutorial$ zip function.zip function.sh bootstrap adding: function.sh (deflated 24%) adding: bootstrap (deflated 39%) ``` Create a function named `bash-runtime`\. ``` runtime-tutorial$ aws lambda create-function --function-name bash-runtime \ --zip-file fileb://function.zip --handler function.handler --runtime provided \ --role arn:aws:iam::123456789012:role/lambda-role { "FunctionName": "bash-runtime", "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:bash-runtime", "Runtime": "provided", "Role": "arn:aws:iam::123456789012:role/lambda-role", "Handler": "function.handler",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
4cd6ba7983f7-2
"Handler": "function.handler", "CodeSha256": "mv/xRv84LPCxdpcbKvmwuuFzwo7sLwUO1VxcUv3wKlM=", "Version": "$LATEST", "TracingConfig": { "Mode": "PassThrough" }, "RevisionId": "2e1d51b0-6144-4763-8e5c-7d5672a01713", ... } ``` Invoke the function and verify the response\. ``` runtime-tutorial$ aws lambda invoke --function-name bash-runtime --payload '{"text":"Hello"}' response.txt { "StatusCode": 200, "ExecutedVersion": "$LATEST" } runtime-tutorial$ cat response.txt Echoing request: '{"text":"Hello"}' ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
d35e2edde4c9-0
To separate the runtime code from the function code, create a layer that only contains the runtime\. Layers let you develop your function's dependencies independently, and can reduce storage usage when you use the same layer with multiple functions\. Create a layer archive that contains the `bootstrap` file\. ``` runtime-tutorial$ zip runtime.zip bootstrap adding: bootstrap (deflated 39%) ``` Create a layer with the `publish-layer-version` command\. ``` runtime-tutorial$ aws lambda publish-layer-version --layer-name bash-runtime --zip-file fileb://runtime.zip { "Content": { "Location": "https://awslambda-us-west-2-layers.s3.us-west-2.amazonaws.com/snapshots/123456789012/bash-runtime-018c209b...", "CodeSha256": "bXVLhHi+D3H1QbDARUVPrDwlC7bssPxySQqt1QZqusE=", "CodeSize": 584, "UncompressedCodeSize": 0 }, "LayerArn": "arn:aws:lambda:us-west-2:123456789012:layer:bash-runtime",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
d35e2edde4c9-1
"LayerArn": "arn:aws:lambda:us-west-2:123456789012:layer:bash-runtime", "LayerVersionArn": "arn:aws:lambda:us-west-2:123456789012:layer:bash-runtime:1", "Description": "", "CreatedDate": "2018-11-28T07:49:14.476+0000", "Version": 1 } ``` This creates the first version of the layer\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
98d21748422e-0
To use the runtime layer with the function, configure the function to use the layer, and remove the runtime code from the function\. Update the function configuration to pull in the layer\. ``` runtime-tutorial$ aws lambda update-function-configuration --function-name bash-runtime \ --layers arn:aws:lambda:us-west-2:123456789012:layer:bash-runtime:1 { "FunctionName": "bash-runtime", "Layers": [ { "Arn": "arn:aws:lambda:us-west-2:123456789012:layer:bash-runtime:1", "CodeSize": 584, "UncompressedCodeSize": 679 } ] ... } ``` This adds the runtime to the function in the `/opt` directory\. Lambda uses this runtime, but only if you remove it from the function's deployment package\. Update the function code to only include the handler script\. ``` runtime-tutorial$ zip function-only.zip function.sh adding: function.sh (deflated 24%) runtime-tutorial$ aws lambda update-function-code --function-name bash-runtime --zip-file fileb://function-only.zip {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
98d21748422e-1
{ "FunctionName": "bash-runtime", "CodeSize": 270, "Layers": [ { "Arn": "arn:aws:lambda:us-west-2:123456789012:layer:bash-runtime:7", "CodeSize": 584, "UncompressedCodeSize": 679 } ] ... } ``` Invoke the function to verify that it works with the runtime layer\. ``` runtime-tutorial$ aws lambda invoke --function-name bash-runtime --payload '{"text":"Hello"}' response.txt { "StatusCode": 200, "ExecutedVersion": "$LATEST" } runtime-tutorial$ cat response.txt Echoing request: '{"text":"Hello"}' ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
92a8d24d4d38-0
To log information about the execution environment, update the runtime script to output environment variables\. **Example bootstrap** ``` #!/bin/sh set -euo pipefail echo "## Environment variables:" env
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
3791c9a9a01e-0
source $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f1).sh" ... ``` Create a second version of the layer with the new code\. ``` runtime-tutorial$ zip runtime.zip bootstrap updating: bootstrap (deflated 39%) runtime-tutorial$ aws lambda publish-layer-version --layer-name bash-runtime --zip-file fileb://runtime.zip ``` Configure the function to use the new version of the layer\. ``` runtime-tutorial$ aws lambda update-function-configuration --function-name bash-runtime \ --layers arn:aws:lambda:us-west-2:123456789012:layer:bash-runtime:2 ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
1779f82bc501-0
Add a permission statement to your runtime layer to share it with other accounts\. ``` runtime-tutorial$ aws lambda add-layer-version-permission --layer-name bash-runtime --version-number 2 \ --principal "*" --statement-id publish --action lambda:GetLayerVersion { "Statement": "{\"Sid\":\"publish\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"lambda:GetLayerVersion\",\"Resource\":\"arn:aws:lambda:us-west-2:123456789012:layer:bash-runtime:2\"}", "RevisionId": "9d5fe08e-2a1e-4981-b783-37ab551247ff" } ``` You can add multiple statements that each grant permission to a single account, accounts in an organization, or all accounts\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
9a43936adde0-0
Delete each version of the layer\. ``` runtime-tutorial$ aws lambda delete-layer-version --layer-name bash-runtime --version-number 1 runtime-tutorial$ aws lambda delete-layer-version --layer-name bash-runtime --version-number 2 ``` Because the function holds a reference to version 2 of the layer, it still exists in Lambda\. The function continues to work, but functions can no longer be configured to use the deleted version\. If you then modify the list of layers on the function, you must specify a new version or omit the deleted layer\. Delete the tutorial function with the `delete-function` command\. ``` runtime-tutorial$ aws lambda delete-function --function-name bash-runtime ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-walkthrough.md
b899bab164b8-0
You can use the AWS Lambda API or console to configure settings on your Lambda functions\. [Basic function settings](configuration-console.md) include the description, role, and runtime that you specify when you create a function in the Lambda console\. You can configure more settings after you create a function, or use the API to set things like the handler name, memory allocation, and security groups during creation\. To keep secrets out of your function code, store them in the function's configuration and read them from the execution environment during initialization\. [Environment variables](configuration-envvars.md) are always encrypted at rest, and can be encrypted client\-side as well\. Use environment variables to make your function code portable by removing connection strings, passwords, and endpoints for external resources\. [Versions and aliases](configuration-versions.md) are secondary resources that you can create to manage function deployment and invocation\. Publish [versions](configuration-versions.md) of your function to store its code and configuration as a separate resource that cannot be changed, and create an [alias](configuration-aliases.md) that points to a specific version\. Then you can configure your clients to invoke a function alias, and update the alias when you want to point the client to a new version, instead of updating the client\. As you add libraries and other dependencies to your function, creating and uploading a deployment package can slow down development\. Use [layers](configuration-layers.md) to manage your function's dependencies independently and keep your deployment package small\. You can also use layers to share your own libraries with other customers and use publicly available layers with your functions\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-functions.md
b899bab164b8-1
To use your Lambda function with AWS resources in an Amazon VPC, configure it with security groups and subnets to [create a VPC connection](configuration-vpc.md)\. Connecting your function to a VPC lets you access resources in a private subnet such as relational databases and caches\. You can also [create a database proxy](configuration-database.md) for MySQL and Aurora DB instances\. A database proxy enables a function to reach high concurrency levels without exhausting database connections\. **Topics** + [Configuring functions in the AWS Lambda console](configuration-console.md) + [Using AWS Lambda environment variables](configuration-envvars.md) + [Managing concurrency for a Lambda function](configuration-concurrency.md) + [Lambda function versions](configuration-versions.md) + [Lambda function aliases](configuration-aliases.md) + [AWS Lambda layers](configuration-layers.md) + [Configuring a Lambda function to access resources in a VPC](configuration-vpc.md) + [Configuring database access for a Lambda function](configuration-database.md) + [Configuring file system access for Lambda functions](configuration-filesystem.md) + [Tagging Lambda Functions](configuration-tags.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-functions.md
b51e29853a74-0
You can use an AWS Lambda function to process records in an [Amazon Kinesis data stream](https://docs.aws.amazon.com/kinesis/latest/dev/amazon-kinesis-streams.html)\. A Kinesis data stream is a set of [shards](https://docs.aws.amazon.com/streams/latest/dev/key-concepts.html#shard)\. Each shard contains a sequence of data records\. A **consumer** is an application that processes the data from a Kinesis data stream\. You can map a Lambda function to a shared\-throughput consumer \(standard iterator\), or to a dedicated\-throughput consumer with [enhanced fan\-out](https://docs.aws.amazon.com/kinesis/latest/dev/enhanced-consumers.html)\. For standard iterators, Lambda polls each shard in your Kinesis stream for records using HTTP protocol\. The event source mapping shares read throughput with other consumers of the shard\. To minimize latency and maximize read throughput, you can create a data stream consumer with enhanced fan\-out\. Stream consumers get a dedicated connection to each shard that doesn't impact other applications reading from the stream\. The dedicated throughput can help if you have many applications reading the same data, or if you're reprocessing a stream with large records\. Kinesis pushes records to Lambda over HTTP/2\. For details about Kinesis data streams, see [Reading Data from Amazon Kinesis Data Streams](https://docs.aws.amazon.com/kinesis/latest/dev/building-consumers.html)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b51e29853a74-1
**Note** Error handling is not available for HTTP/2 stream consumers\. Lambda reads records from the data stream and invokes your function [synchronously](invocation-sync.md) with an event that contains stream records\. Lambda reads records in batches and invokes your function to process records from the batch\. **Example Kinesis record event** ``` { "Records": [ { "kinesis": { "kinesisSchemaVersion": "1.0", "partitionKey": "1", "sequenceNumber": "49590338271490256608559692538361571095921575989136588898", "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0Lg==", "approximateArrivalTimestamp": 1545084650.987 }, "eventSource": "aws:kinesis", "eventVersion": "1.0", "eventID": "shardId-000000000006:49590338271490256608559692538361571095921575989136588898", "eventName": "aws:kinesis:record",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b51e29853a74-2
"eventName": "aws:kinesis:record", "invokeIdentityArn": "arn:aws:iam::123456789012:role/lambda-role", "awsRegion": "us-east-2", "eventSourceARN": "arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream" }, { "kinesis": { "kinesisSchemaVersion": "1.0", "partitionKey": "1", "sequenceNumber": "49590338271490256608559692540925702759324208523137515618", "data": "VGhpcyBpcyBvbmx5IGEgdGVzdC4=", "approximateArrivalTimestamp": 1545084711.166 }, "eventSource": "aws:kinesis", "eventVersion": "1.0", "eventID": "shardId-000000000006:49590338271490256608559692540925702759324208523137515618", "eventName": "aws:kinesis:record",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b51e29853a74-3
"eventName": "aws:kinesis:record", "invokeIdentityArn": "arn:aws:iam::123456789012:role/lambda-role", "awsRegion": "us-east-2", "eventSourceARN": "arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream" } ] } ``` By default, Lambda invokes your function as soon as records are available in the stream\. If the batch that Lambda reads from the stream only has one record in it, Lambda sends only one record to the function\. To avoid invoking the function with a small number of records, you can tell the event source to buffer records for up to five minutes by configuring a *batch window*\. Before invoking the function, Lambda continues to read records from the stream until it has gathered a full batch, or until the batch window expires\. If your function returns an error, Lambda retries the batch until processing succeeds or the data expires\. To avoid stalled shards, you can configure the event source mapping to retry with a smaller batch size, limit the number of retries, or discard records that are too old\. To retain discarded events, you can configure the event source mapping to send details about failed batches to an SQS queue or SNS topic\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b51e29853a74-4
You can also increase concurrency by processing multiple batches from each shard in parallel\. Lambda can process up to 10 batches in each shard simultaneously\. If you increase the number of concurrent batches per shard, Lambda still ensures in\-order processing at the partition\-key level\. **Topics** + [Configuring your data stream and function](#services-kinesis-configure) + [Execution role permissions](#events-kinesis-permissions) + [Configuring a stream as an event source](#services-kinesis-eventsourcemapping) + [Event source mapping API](#services-kinesis-api) + [Error handling](#services-kinesis-errors) + [Amazon CloudWatch metrics](#events-kinesis-metrics) + [Tutorial: Using AWS Lambda with Amazon Kinesis](with-kinesis-example.md) + [Sample function code](with-kinesis-create-package.md) + [AWS SAM template for a Kinesis application](with-kinesis-example-use-app-spec.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b70d867ec468-0
Your Lambda function is a consumer application for your data stream\. It processes one batch of records at a time from each shard\. You can map a Lambda function to a data stream \(standard iterator\), or to a consumer of a stream \([enhanced fan\-out](https://docs.aws.amazon.com/kinesis/latest/dev/enhanced-consumers.html)\)\. For standard iterators, Lambda polls each shard in your Kinesis stream for records at a base rate of once per second\. When more records are available, Lambda keeps processing batches until the function catches up with the stream\. The event source mapping shares read throughput with other consumers of the shard\. To minimize latency and maximize read throughput, create a data stream consumer with enhanced fan\-out\. Enhanced fan\-out consumers get a dedicated connection to each shard that doesn't impact other applications reading from the stream\. Stream consumers use HTTP/2 to reduce latency by pushing records to Lambda over a long\-lived connection and by compressing request headers\. You can create a stream consumer with the Kinesis [RegisterStreamConsumer](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_RegisterStreamConsumer.html) API\. ``` $ aws kinesis register-stream-consumer --consumer-name con1 \ --stream-arn arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream { "Consumer": {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b70d867ec468-1
{ "Consumer": { "ConsumerName": "con1", "ConsumerARN": "arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream/consumer/con1:1540591608", "ConsumerStatus": "CREATING", "ConsumerCreationTimestamp": 1540591608.0 } } ``` To increase the speed at which your function processes records, add shards to your data stream\. Lambda processes records in each shard in order\. It stops processing additional records in a shard if your function returns an error\. With more shards, there are more batches being processed at once, which lowers the impact of errors on concurrency\. If your function can't scale up to handle the total number of concurrent batches, [request a quota increase](gettingstarted-limits.md) or [reserve concurrency](configuration-concurrency.md) for your function\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
ae456de990a5-0
Lambda needs the following permissions to manage resources that are related to your Kinesis data stream\. Add them to your function's [execution role](lambda-intro-execution-role.md)\. + [kinesis:DescribeStream](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_DescribeStream.html) + [kinesis:DescribeStreamSummary](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_DescribeStreamSummary.html) + [kinesis:GetRecords](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetRecords.html) + [kinesis:GetShardIterator](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html) + [kinesis:ListShards](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_ListShards.html) + [kinesis:ListStreams](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_ListStreams.html) + [kinesis:SubscribeToShard](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_SubscribeToShard.html)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
ae456de990a5-1
The `AWSLambdaKinesisExecutionRole` managed policy includes these permissions\. For more information, see [AWS Lambda execution role](lambda-intro-execution-role.md)\. To send records of failed batches to a queue or topic, your function needs additional permissions\. Each destination service requires a different permission, as follows: + **Amazon SQS** – [sqs:SendMessage](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html) + **Amazon SNS** – [sns:Publish](https://docs.aws.amazon.com/sns/latest/api/API_Publish.html)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
a3940f204236-0
Create an event source mapping to tell Lambda to send records from your data stream to a Lambda function\. You can create multiple event source mappings to process the same data with multiple Lambda functions, or to process items from multiple data streams with a single function\. To configure your function to read from Kinesis in the Lambda console, create a **Kinesis** trigger\. **To create a trigger** 1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\. 1. Choose a function\. 1. Under **Designer**, choose **Add trigger**\. 1. Choose a trigger type\. 1. Configure the required options and then choose **Add**\. Lambda supports the following options for Kinesis event sources\. **Event source options** + **Kinesis stream** – The Kinesis stream to read records from\. + **Consumer** \(optional\) – Use a stream consumer to read from the stream over a dedicated connection\. + **Batch size** – The number of records to send to the function in each batch, up to 10,000\. Lambda passes all of the records in the batch to the function in a single call, as long as the total size of the events doesn't exceed the [payload limit](gettingstarted-limits.md) for synchronous invocation \(6 MB\)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
a3940f204236-1
+ **Batch window** – Specify the maximum amount of time to gather records before invoking the function, in seconds\. + **Starting position** – Process only new records, all existing records, or records created after a certain date\. + **Latest** – Process new records that are added to the stream\. + **Trim horizon** – Process all records in the stream\. + **At timestamp** – Process records starting from a specific time\. After processing any existing records, the function is caught up and continues to process new records\. + **On\-failure destination** – An SQS queue or SNS topic for records that can't be processed\. When Lambda discards a batch of records because it's too old or has exhausted all retries, it sends details about the batch to the queue or topic\. + **Retry attempts** – The maximum number of times that Lambda retries when the function returns an error\. This doesn't apply to service errors or throttles where the batch didn't reach the function\. + **Maximum age of record** – The maximum age of a record that Lambda sends to your function\. + **Split batch on error** – When the function returns an error, split the batch into two before retrying\. + **Concurrent batches per shard** – Process multiple batches from the same shard concurrently\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
a3940f204236-2
+ **Concurrent batches per shard** – Process multiple batches from the same shard concurrently\. + **Enabled** – Set to true to enable the event source mapping\. Set to false to stop processing records\. Lambda keeps track of the last record processed and resumes processing from that point when it's reenabled\. **Note** Kinesis charges for each shard and, for enhanced fan\-out, data read from the stream\. For pricing details, see [Amazon Kinesis pricing](https://aws.amazon.com/kinesis/data-streams/pricing)\. To manage the event source configuration later, choose the trigger in the designer\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b5b96e9df7ea-0
To manage event source mappings with the AWS CLI or AWS SDK, use the following API actions: + [CreateEventSourceMapping](API_CreateEventSourceMapping.md) + [ListEventSourceMappings](API_ListEventSourceMappings.md) + [GetEventSourceMapping](API_GetEventSourceMapping.md) + [UpdateEventSourceMapping](API_UpdateEventSourceMapping.md) + [DeleteEventSourceMapping](API_DeleteEventSourceMapping.md) To create the event source mapping with the AWS CLI, use the `create-event-source-mapping` command\. The following example uses the AWS CLI to map a function named `my-function` to a Kinesis data stream\. The data stream is specified by an Amazon Resource Name \(ARN\), with a batch size of 500, starting from the timestamp in Unix time\. ``` $ aws lambda create-event-source-mapping --function-name my-function \ --batch-size 500 --starting-position AT_TIMESTAMP --starting-position-timestamp 1541139109 \ --event-source-arn arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b5b96e9df7ea-1
{ "UUID": "2b733gdc-8ac3-cdf5-af3a-1827b3b11284", "BatchSize": 500, "MaximumBatchingWindowInSeconds": 0, "ParallelizationFactor": 1, "EventSourceArn": "arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream", "FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function", "LastModified": 1541139209.351, "LastProcessingResult": "No records processed", "State": "Creating", "StateTransitionReason": "User action", "DestinationConfig": {}, "MaximumRecordAgeInSeconds": 604800, "BisectBatchOnFunctionError": false, "MaximumRetryAttempts": 10000 } ``` To use a consumer, specify the consumer's ARN instead of the stream's ARN\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b5b96e9df7ea-2
} ``` To use a consumer, specify the consumer's ARN instead of the stream's ARN\. Configure additional options to customize how batches are processed and to specify when to discard records that can't be processed\. The following example updates an event source mapping to send a failure record to an SQS queue after two retry attempts, or if the records are more than an hour old\. ``` $ aws lambda update-event-source-mapping --uuid f89f8514-cdd9-4602-9e1f-01a5b77d449b \ --maximum-retry-attempts 2 --maximum-record-age-in-seconds 3600 --destination-config '{"OnFailure": {"Destination": "arn:aws:sqs:us-east-2:123456789012:dlq"}}' { "UUID": "f89f8514-cdd9-4602-9e1f-01a5b77d449b", "BatchSize": 100, "MaximumBatchingWindowInSeconds": 0, "ParallelizationFactor": 1, "EventSourceArn": "arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b5b96e9df7ea-3
"EventSourceArn": "arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream", "FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function", "LastModified": 1573243620.0, "LastProcessingResult": "PROBLEM: Function call failed", "State": "Updating", "StateTransitionReason": "User action", "DestinationConfig": {}, "MaximumRecordAgeInSeconds": 604800, "BisectBatchOnFunctionError": false, "MaximumRetryAttempts": 10000 } ``` Updated settings are applied asynchronously and aren't reflected in the output until the process completes\. Use the `get-event-source-mapping` command to view the current status\. ``` $ aws lambda get-event-source-mapping --uuid f89f8514-cdd9-4602-9e1f-01a5b77d449b { "UUID": "f89f8514-cdd9-4602-9e1f-01a5b77d449b", "BatchSize": 100,
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b5b96e9df7ea-4
"BatchSize": 100, "MaximumBatchingWindowInSeconds": 0, "ParallelizationFactor": 1, "EventSourceArn": "arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream", "FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function", "LastModified": 1573244760.0, "LastProcessingResult": "PROBLEM: Function call failed", "State": "Enabled", "StateTransitionReason": "User action", "DestinationConfig": { "OnFailure": { "Destination": "arn:aws:sqs:us-east-2:123456789012:dlq" } }, "MaximumRecordAgeInSeconds": 3600, "BisectBatchOnFunctionError": false, "MaximumRetryAttempts": 2 } ``` To process multiple batches concurrently, use the `--parallelization-factor` option\. ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
b5b96e9df7ea-5
``` To process multiple batches concurrently, use the `--parallelization-factor` option\. ``` $ aws lambda update-event-source-mapping --uuid 2b733gdc-8ac3-cdf5-af3a-1827b3b11284 \ --parallelization-factor 5 ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
7fc7d9282da5-0
The event source mapping that reads records from your Kinesis stream invokes your function synchronously and retries on errors\. If the function is throttled or the Lambda service returns an error without invoking the function, Lambda retries until the records expire or exceed the maximum age that you configure on the event source mapping\. If the function receives the records but returns an error, Lambda retries until the records in the batch expire, exceed the maximum age, or reach the configured retry quota\. For function errors, you can also configure the event source mapping to split a failed batch into two batches\. Retrying with smaller batches isolates bad records and works around timeout issues\. Splitting a batch does not count towards the retry quota\. If the error handling measures fail, Lambda discards the records and continues processing batches from the stream\. With the default settings, this means that a bad record can block processing on the affected shard for up to one week\. To avoid this, configure your function's event source mapping with a reasonable number of retries and a maximum record age that fits your use case\. To retain a record of discarded batches, configure a failed\-event destination\. Lambda sends a document to the destination queue or topic with details about the batch\. **To configure a destination for failed\-event records** 1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\. 1. Choose a function\. 1. Under **Designer**, choose **Add destination**\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
7fc7d9282da5-1
1. Choose a function\. 1. Under **Designer**, choose **Add destination**\. 1. For **Source**, choose **Stream invocation**\. 1. For **Stream**, choose a stream that is mapped to the function\. 1. For **Destination type**, choose the type of resource that receives the invocation record\. 1. For **Destination**, choose a resource\. 1. Choose **Save**\. The following example shows an invocation record for a Kinesis stream\. **Example invocation Record** ``` { "requestContext": { "requestId": "c9b8fa9f-5a7f-xmpl-af9c-0c604cde93a5", "functionArn": "arn:aws:lambda:us-east-2:123456789012:function:myfunction", "condition": "RetryAttemptsExhausted", "approximateInvokeCount": 1 }, "responseContext": { "statusCode": 200, "executedVersion": "$LATEST", "functionError": "Unhandled" }, "version": "1.0",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
7fc7d9282da5-2
"functionError": "Unhandled" }, "version": "1.0", "timestamp": "2019-11-14T00:38:06.021Z", "KinesisBatchInfo": { "shardId": "shardId-000000000001", "startSequenceNumber": "49601189658422359378836298521827638475320189012309704722", "endSequenceNumber": "49601189658422359378836298522902373528957594348623495186", "approximateArrivalOfFirstRecord": "2019-11-14T00:38:04.835Z", "approximateArrivalOfLastRecord": "2019-11-14T00:38:05.580Z", "batchSize": 500, "streamArn": "arn:aws:kinesis:us-east-2:123456789012:stream/mystream" } } ``` You can use this information to retrieve the affected records from the stream for troubleshooting\. The actual records aren't included, so you must process this record and retrieve them from the stream before they expire and are lost\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
6fad2ca74f34-0
Lambda emits the `IteratorAge` metric when your function finishes processing a batch of records\. The metric indicates how old the last record in the batch was when processing finished\. If your function is processing new events, you can use the iterator age to estimate the latency between when a record is added and when the function processes it\. An increasing trend in iterator age can indicate issues with your function\. For more information, see [Working with AWS Lambda function metrics](monitoring-metrics.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis.md
d81a3c5f3c89-0
This section shows how to package your Java code into a deployment package using Eclipse IDE and Maven plugin for Eclipse\. **Note** The AWS SDK Eclipse Toolkit provides an Eclipse plugin for you to both create a deployment package and also upload it to create a Lambda function\. If you can use Eclipse IDE as your development environment, this plugin enables you to author Java code, create and upload a deployment package, and create your Lambda function\. For more information, see the [AWS Toolkit for Eclipse Getting Started Guide](https://docs.aws.amazon.com/AWSToolkitEclipse/latest/GettingStartedGuide/)\. For an example of using the toolkit for authoring Lambda functions, see [Using AWS Lambda with the AWS toolkit for Eclipse](https://docs.aws.amazon.com/AWSToolkitEclipse/latest/GettingStartedGuide/lambda.html)\. **Topics** + [Prerequisites](#java-package-eclipse-prereqs) + [Create and build a project](#java-package-eclipse-create)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package-eclipse.md
0aeb6399a465-0
Install the **Maven** Plugin for Eclipse\. 1. Start Eclipse\. From the **Help** menu in Eclipse, choose **Install New Software**\. 1. In the **Install** window, type **http://download\.eclipse\.org/technology/m2e/releases** in the **Work with:** box, and choose **Add**\. 1. Follow the steps to complete the setup\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package-eclipse.md
d6942ac4393a-0
In this step, you start Eclipse and create a Maven project\. You will add the necessary dependencies, and build the project\. The build will produce a \.jar, which is your deployment package\. 1. Create a new Maven project in Eclipse\. 1. From the **File** menu, choose **New**, and then choose **Project**\. 1. In the **New Project** window, choose **Maven Project**\. 1. In the **New Maven Project** window, choose **Create a simple project**, and leave other default selections\. 1. In the **New Maven Project**, **Configure project** windows, type the following **Artifact** information: + **Group Id**: doc\-examples + **Artifact Id**: lambda\-java\-example + **Version**: 0\.0\.1\-SNAPSHOT + **Packaging**: jar + **Name**: lambda\-java\-example 1. Add the `aws-lambda-java-core` dependency to the `pom.xml` file\. It provides definitions of the `RequestHandler`, `RequestStreamHandler`, and `Context` interfaces\. This allows you to compile code that you can use with AWS Lambda\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package-eclipse.md
d6942ac4393a-1
1. Open the context \(right\-click\) menu for the `pom.xml` file, choose **Maven**, and then choose **Add Dependency**\. 1. In the **Add Dependency** windows, type the following values: **Group Id:** com\.amazonaws **Artifact Id:** aws\-lambda\-java\-core **Version:** 1\.2\.1 **Note** If you are following other tutorial topics in this guide, the specific tutorials might require you to add more dependencies\. Make sure to add those dependencies as required\. 1. Add Java class to the project\. 1. Open the context \(right\-click\) menu for the `src/main/java` subdirectory in the project, choose **New**, and then choose **Class**\. 1. In the **New Java Class** window, type the following values: + **Package**: **example** + **Name**: **Hello** **Note** If you are following other tutorial topics in this guide, the specific tutorials might recommend different package name or class name\. 1. Add your Java code\. If you are following other tutorial topics in this guide, add the provided code\. 1. Build the project\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package-eclipse.md
d6942ac4393a-2
1. Add your Java code\. If you are following other tutorial topics in this guide, add the provided code\. 1. Build the project\. Open the context \(right\-click\) menu for the project in **Package Explorer**, choose **Run As**, and then choose **Maven Build \.\.\.**\. In the **Edit Configuration** window, type **package** in the **Goals** box\. **Note** The resulting \.jar, `lambda-java-example-0.0.1-SNAPSHOT.jar`, is not the final standalone \.jar that you can use as your deployment package\. In the next step, you add the Apache `maven-shade-plugin` to create the standalone \.jar\. For more information, go to [Apache Maven Shade plugin](https://maven.apache.org/plugins/maven-shade-plugin/)\. 1. Add the `maven-shade-plugin` plugin and rebuild\. The maven\-shade\-plugin will take artifacts \(jars\) produced by the *package* goal \(produces customer code \.jar\), and created a standalone \.jar that contains the compiled customer code, and the resolved dependencies from the `pom.xml`\. 1. Open the context \(right\-click\) menu for the `pom.xml` file, choose **Maven**, and then choose **Add Plugin**\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package-eclipse.md
d6942ac4393a-3
1. In the **Add Plugin** window, type the following values: + **Group Id:** org\.apache\.maven\.plugins + **Artifact Id:** maven\-shade\-plugin + **Version:** 3\.2\.2 1. Now build again\. This time we will create the jar as before, and then use the `maven-shade-plugin` to pull in dependencies to make the standalone \.jar\. 1. Open the context \(right\-click\) menu for the project, choose **Run As**, and then choose **Maven build \.\.\.**\. 1. In the **Edit Configuration** windows, type **package shade:shade** in the **Goals** box\. 1. Choose `Run`\. You can find the resulting standalone \.jar \(that is, your deployment package\), in the `/target `subdirectory\. Open the context \(right\-click\) menu for the `/target` subdirectory, choose **Show In**, choose **System Explorer**, and you will find the `lambda-java-example-0.0.1-SNAPSHOT.jar`\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package-eclipse.md
c51c48fb2cca-0
In this tutorial, you do the following: + Create a Lambda function using the **lambda\-canary** blueprint\. You configure the Lambda function to run every minute\. Note that if the function returns an error, AWS Lambda logs error metrics to CloudWatch\. + Configure a CloudWatch alarm on the `Errors` metric of your Lambda function to post a message to your Amazon SNS topic when AWS Lambda emits error metrics to CloudWatch\. You subscribe to the Amazon SNS topics to get email notification\. In this tutorial, you do the following to set this up: + Create an Amazon SNS topic\. + Subscribe to the topic so you can get email notifications when a new message is posted to the topic\. + In Amazon CloudWatch, set an alarm on the `Errors` metric of your Lambda function to publish a message to your SNS topic when errors occur\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudwatchevents-tutorial.md
208836465c44-0
This tutorial assumes that you have some knowledge of basic Lambda operations and the Lambda console\. If you haven't already, follow the instructions in [Getting started with AWS Lambda](getting-started.md) to create your first Lambda function\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudwatchevents-tutorial.md
b99f6179e9e0-0
1. Sign in to the AWS Management Console and open the AWS Lambda console at [https://console\.aws\.amazon\.com/lambda/](https://console.aws.amazon.com/lambda/)\. 1. Choose **Create function**\. 1. Choose **Blueprints**\. 1. Enter **canary** in the search bar\. Choose the **lambda\-canary** blueprint, and then choose **Configure**\. 1. Configure the following settings\. + **Name** – **lambda\-canary**\. + **Role** – **Create a new role from one or more templates**\. + **Role name** – **lambda\-apigateway\-role**\. + **Policy templates** – **Simple microservice permissions**\. + **Rule** – **Create a new rule**\. + **Rule name** – **CheckWebsiteScheduledEvent**\. + **Rule description** – **CheckWebsiteScheduledEvent trigger**\. + **Schedule expression** – **rate\(1 minute\)**\. + **Enabled** – True \(checked\)\. + **Environment variables**
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudwatchevents-tutorial.md
b99f6179e9e0-1
+ **Enabled** – True \(checked\)\. + **Environment variables** + **site** – **https://docs\.aws\.amazon\.com/lambda/latest/dg/welcome\.html**\. + **expected** – **What is AWS Lambda?**\. 1. Choose **Create function**\. CloudWatch Events emits an event every minute, based on the schedule expression\. The event triggers the Lambda function, which verifies that the expected string appears in the specified page\. For more information on expressions schedules, see [Schedule expressions using rate or cron](services-cloudwatchevents-expressions.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudwatchevents-tutorial.md
91d54034595c-0
Test the function with a sample event provided by the Lambda console\. 1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\. 1. Choose **lambda\-canary**\. 1. Next to the **Test** button at the top of the page, choose **Configure test events** from the drop\-down menu\. 1. Create a new event using the **CloudWatch Events** event template\. 1. Choose **Create**\. 1. Choose **Test**\. The output from the function execution is shown at the top of the page\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudwatchevents-tutorial.md
f973710e8e79-0
Create an Amazon Simple Notification Service \(Amazon SNS\) topic to receive notifications when the canary function returns an error\. **To create a topic** 1. Open the [Amazon SNS console](https://console.aws.amazon.com/sns/home)\. 1. Choose **Create topic**\. 1. Create a topic with the following settings\. + **Name** – **lambda\-canary\-notifications**\. + **Display name** – **Canary**\. 1. Choose **Create subscription**\. 1. Create a subscription with the following settings\. + **Protocol** – **Email**\. + **Endpoint** – Your email address\. Amazon SNS sends an email from `Canary <no-reply@sns.amazonaws.com>`, reflecting the friendly name of the topic\. Use the link in the email to confirm your address\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudwatchevents-tutorial.md
ee38b26f5909-0
Configure an alarm in Amazon CloudWatch that monitors the Lambda function and sends a notification when it fails\. **To create an alarm** 1. Open the [CloudWatch console](https://console.aws.amazon.com/cloudwatch)\. 1. Choose **Alarms**\. 1. Choose **Create alarm**\. 1. Choose **Alarms**\. 1. Create an alarm with the following settings\. + **Metrics** – **lambda\-canary Errors**\. Search for **lambda canary errors** to find the metric\. + Statistic – **Sum**\. Choose the statistic from the drop\-down menu above the preview graph\. + **Name** – **lambda\-canary\-alarm**\. + **Description** – **Lambda canary alarm**\. + Threshold – **Whenever Errors is >=****1**\. + **Send notification to** – **lambda\-canary\-notifications**\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudwatchevents-tutorial.md
376e5ba10baa-0
Update the function configuration to cause the function to return an error, which triggers the alarm\. **To trigger an alarm** 1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\. 1. Choose **lambda\-canary**\. 1. Under **Environment variables**, choose **Edit**\. 1. Set **expected** to **404**\. 1. Choose **Save**\. Wait a minute, and then check your email for a message from Amazon SNS\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudwatchevents-tutorial.md
f2e132bd2541-0
You can restrict the scope of a user's permissions by specifying resources and conditions in an IAM policy\. Each API action supports a combination of resource and condition types that varies depending on the behavior of the action\. Every IAM policy statement grants permission to an action that's performed on a resource\. When the action doesn't act on a named resource, or when you grant permission to perform the action on all resources, the value of the resource in the policy is a wildcard \(`*`\)\. For many API actions, you can restrict the resources that a user can modify by specifying the Amazon Resource Name \(ARN\) of a resource, or an ARN pattern that matches multiple resources\. To restrict permissions by resource, specify the resource by ARN\. **Lambda resource ARN format** + Function – `arn:aws:lambda:us-west-2:123456789012:function:my-function` + Function version – `arn:aws:lambda:us-west-2:123456789012:function:my-function:1` + Function alias – `arn:aws:lambda:us-west-2:123456789012:function:my-function:TEST` + Event source mapping – `arn:aws:lambda:us-west-2:123456789012:event-source-mapping:fa123456-14a1-4fd2-9fec-83de64ad683de6d47`
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
f2e132bd2541-1
+ Layer – `arn:aws:lambda:us-west-2:123456789012:layer:my-layer` + Layer version – `arn:aws:lambda:us-west-2:123456789012:layer:my-layer:1` For example, the following policy allows a user in account `123456789012` to invoke a function named `my-function` in the US West \(Oregon\) Region\. **Example invoke function policy** ``` { "Version": "2012-10-17", "Statement": [ { "Sid": "Invoke", "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], "Resource": "arn:aws:lambda:us-west-2:123456789012:function:my-function" } ] } ``` This is a special case where the action identifier \(`lambda:InvokeFunction`\) differs from the API operation \([Invoke](API_Invoke.md)\)\. For other actions, the action identifier is the operation name prefixed by `lambda:`\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
f2e132bd2541-2
Conditions are an optional policy element that applies additional logic to determine if an action is allowed\. In addition to [common conditions](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html) supported by all actions, Lambda defines condition types that you can use to restrict the values of additional parameters on some actions\. For example, the `lambda:Principal` condition lets you restrict the service or account that a user can grant invocation access to on a function's resource\-based policy\. The following policy lets a user grant permission to SNS topics to invoke a function named `test`\. **Example manage function policy permissions** ``` { "Version": "2012-10-17", "Statement": [ { "Sid": "ManageFunctionPolicy", "Effect": "Allow", "Action": [ "lambda:AddPermission", "lambda:RemovePermission" ], "Resource": "arn:aws:lambda:us-west-2:123456789012:function:test:*", "Condition": { "StringEquals": { "lambda:Principal": "sns.amazonaws.com" } } } ] } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
f2e132bd2541-3
} } } ] } ``` The condition requires that the principal is Amazon SNS and not another service or account\. The resource pattern requires that the function name is `test` and includes a version number or alias\. For example, `test:v1`\. For more information on resources and conditions for Lambda and other AWS services, see [Actions, resources, and condition keys](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_actions-resources-contextkeys.html) in the *IAM User Guide*\. **Topics** + [Function resource names](#function-resources) + [Functions](#permissions-resources-function) + [Event source mappings](#permissions-resources-eventsource) + [Layers](#permissions-resources-layers)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
ff640e1418ff-0
You reference a Lambda function in a policy statement using an Amazon Resource Names \(ARN\)\. The format of a function ARN depends on whether you are referencing the whole function, a function [version](configuration-versions.md), or an [alias](configuration-aliases.md)\. When making Lambda API calls, users can specify a version or alias by passing a version ARN or alias ARN in the [https://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html#API_GetFunction_RequestSyntax](https://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html#API_GetFunction_RequestSyntax) parameter, or by setting a value in the [https://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html#API_GetFunction_RequestSyntax](https://docs.aws.amazon.com/lambda/latest/dg/API_GetFunction.html#API_GetFunction_RequestSyntax) parameter\. Lambda makes authorization decisions by comparing the resource element in the IAM policy with the `FunctionName` passed in the API calls\. You must use the correct function ARN types in your policies to achieve the results that you expect, especially in policies that deny access\. We recommend that you follow the best practices for using Deny statements with functions\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
ccfc69662034-0
The following table summarizes the resources to use in Deny effects\. In the **Resource** column, `MyFunction` is the name of the function, `:1` refers to version 1 of the function, and `MyAlias` is the name of a function alias\. **Resource best practices** | Policy objective | Resource | | --- | --- | | Deny access to all versions of a function | `MyFunction*` | | Deny access to a specific alias | `MyFunction:MyAlias` and `MyFunction` | | Deny access to a specific version of a function | `MyFunction:1` and `MyFunction` | The following sections provide example policy statements for each of the policy objectives\. **Note** You can use only identity\-based policies to deny specific function resources\. Currently, Lambda does not support the `Deny` effect in resource\-based policies\. For the action list in a policy statement, you can add any of the [ actions defined by Lambda](https://docs.aws.amazon.com/IAM/latest/UserGuide/list_awslambda.html) that act on a function resource\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
3c0f146062a7-0
The following identity\-based policy statement denies access to the `lambda:GetFunctionConfiguration` action for all versions of the `my-function` function\. The wildcard character at the end of the function ARN ensures that this policy applies to all version and alias ARNs\. **Example identity\-based policy** ``` { "Version": "2020-07-20", "Statement": [ { "Effect": "Deny", "Action": [ "lambda:GetFunctionConfiguration" ], "Resource": "arn:aws:lambda:us-west-2:123456789012:function:my-function*" } ] } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
28098d761f47-0
To deny access to a specific alias, you must specify both the alias ARN and the unqualified function ARN in the policy\. This prevents users from accessing the specific alias by passing the unqualified ARN as the `FunctionName` and the alias as the `Qualifier`\. **Note** If you create this type of policy, API calls need to refer to the unpublished version of the function by specifying a qualified ARN with the $LATEST suffix in the `FunctionName` parameter\. The following identity\-based policy statement denies access to the `lambda:InvokeFunction` action in the `my-alias` alias of the `my-function` function\. **Example identity\-based policy** ``` { "Version": "2012-10-17", "Statement": [ { "Sid": "DenySpecificAlias", "Effect": "Deny", "Action": "lambda:InvokeFunction", "Resource": [ "arn:aws:lambda:us-west-2:123456789012:function:my-function:my-alias", "arn:aws:lambda:us-west-2:123456789012:function:my-function" ] } ] } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
27ae9c6ef60a-0
To deny access to a specific version, you must specify both the qualified ARN and the unqualified ARN in the policy\. This prevents users from accessing the specific version by passing the unqualified ARN as the `FunctionName` and the version as the `Qualifier`\. **Note** If you create this type of policy, API calls need to refer to the unpublished version of the function by specifying a qualified ARN with the $LATEST suffix in the `FunctionName` parameter\. The following identity\-based policy statement denies access to the invoke action in version 1 of the `my-function` function\. **Example identity\-based policy** ``` { "Version": "2012-10-17", "Statement": [ { "Sid": "DenySpecificFunctionVersion", "Effect": "Deny", "Action": [ "lambda:InvokeFunction" ], "Resource": [ "arn:aws:lambda:us-west-2:123456789012:function:my-function:1", "arn:aws:lambda:us-west-2:123456789012:function:my-function" ] } ] } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
5c34cb95d98e-0
Actions that operate on a function can be restricted to a specific function by function, version, or alias ARN, as described in the following table\. Actions that don't support resource restrictions can only be granted for all resources \(`*`\)\. **Functions** | Action | Resource | Condition | | --- | --- | --- | | [AddPermission](API_AddPermission.md) [RemovePermission](API_RemovePermission.md) | Function Function version Function alias | `lambda:Principal` | | [Invoke](API_Invoke.md) **Permission:** `lambda:InvokeFunction` | Function Function version Function alias | None | | [CreateFunction](API_CreateFunction.md) [UpdateFunctionConfiguration](API_UpdateFunctionConfiguration.md) | Function | `lambda:Layer` `lambda:VpcIds` `lambda:SubnetIds` `lambda:SecurityGroupIds` |
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
5c34cb95d98e-1
| [CreateAlias](API_CreateAlias.md) [DeleteAlias](API_DeleteAlias.md) [DeleteFunction](API_DeleteFunction.md) [DeleteFunctionConcurrency](API_DeleteFunctionConcurrency.md) [GetAlias](API_GetAlias.md) [GetFunction](API_GetFunction.md) [GetFunctionConfiguration](API_GetFunctionConfiguration.md) [GetPolicy](API_GetPolicy.md) [ListAliases](API_ListAliases.md) [ListVersionsByFunction](API_ListVersionsByFunction.md) [PublishVersion](API_PublishVersion.md) [PutFunctionConcurrency](API_PutFunctionConcurrency.md) [UpdateAlias](API_UpdateAlias.md) [UpdateFunctionCode](API_UpdateFunctionCode.md) | Function | None | | [GetAccountSettings](API_GetAccountSettings.md) [ListFunctions](API_ListFunctions.md) [ListTags](API_ListTags.md) [TagResource](API_TagResource.md) [UntagResource](API_UntagResource.md) | `*` | None |
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
ba496bbfbd7f-0
For event source mappings, delete and update permissions can be restricted to a specific event source\. The `lambda:FunctionArn` condition lets you restrict which functions a user can configure an event source to invoke\. For these actions, the resource is the event source mapping, so Lambda provides a condition that lets you restrict permission based on the function that the event source mapping invokes\. **Event source mappings** | Action | Resource | Condition | | --- | --- | --- | | [DeleteEventSourceMapping](API_DeleteEventSourceMapping.md) [UpdateEventSourceMapping](API_UpdateEventSourceMapping.md) | Event source mapping | `lambda:FunctionArn` | | [CreateEventSourceMapping](API_CreateEventSourceMapping.md) | `*` | `lambda:FunctionArn` | | [GetEventSourceMapping](API_GetEventSourceMapping.md) [ListEventSourceMappings](API_ListEventSourceMappings.md) | `*` | None |
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
6ea59083bc87-0
Layer actions let you restrict the layers that a user can manage or use with a function\. Actions related to layer use and permissions act on a version of a layer, while `PublishLayerVersion` acts on a layer name\. You can use either with wildcards to restrict the layers that a user can work with by name\. **Note** Note: the [GetLayerVersion](API_GetLayerVersion.md) action also covers [GetLayerVersionByArn](API_GetLayerVersionByArn.md)\. Lambda does not support `GetLayerVersionByArn` as an IAM action\. **Layers** | Action | Resource | Condition | | --- | --- | --- | | [AddLayerVersionPermission](API_AddLayerVersionPermission.md) [RemoveLayerVersionPermission](API_RemoveLayerVersionPermission.md) [GetLayerVersion](API_GetLayerVersion.md) [GetLayerVersionPolicy](API_GetLayerVersionPolicy.md) [DeleteLayerVersion](API_DeleteLayerVersion.md) | Layer version | None | | [ListLayerVersions](API_ListLayerVersions.md) [PublishLayerVersion](API_PublishLayerVersion.md) | Layer | None | | [ListLayers](API_ListLayers.md) | `*` | None |
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-api-permissions-ref.md
b57cb18d7525-0
Lists [AWS Lambda layers](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) and shows information about the latest version of each\. Specify a [runtime identifier](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html) to list only layers that indicate that they're compatible with that runtime\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListLayers.md
29958e859e80-0
``` GET /2018-10-31/layers?CompatibleRuntime=CompatibleRuntime&Marker=Marker&MaxItems=MaxItems HTTP/1.1 ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListLayers.md
babb8147d34f-0
The request uses the following URI parameters\. ** [CompatibleRuntime](#API_ListLayers_RequestSyntax) ** <a name="SSS-ListLayers-request-CompatibleRuntime"></a> A runtime identifier\. For example, `go1.x`\. Valid Values:` nodejs10.x | nodejs12.x | java8 | java8.al2 | java11 | python2.7 | python3.6 | python3.7 | python3.8 | dotnetcore2.1 | dotnetcore3.1 | go1.x | ruby2.5 | ruby2.7 | provided | provided.al2` ** [Marker](#API_ListLayers_RequestSyntax) ** <a name="SSS-ListLayers-request-Marker"></a> A pagination token returned by a previous call\. ** [MaxItems](#API_ListLayers_RequestSyntax) ** <a name="SSS-ListLayers-request-MaxItems"></a> The maximum number of layers to return\. Valid Range: Minimum value of 1\. Maximum value of 50\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListLayers.md
80ca79d71edc-0
The request does not have a request body\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListLayers.md
d1249f909972-0
``` HTTP/1.1 200 Content-type: application/json { "Layers": [ { "LatestMatchingVersion": { "CompatibleRuntimes": [ "string" ], "CreatedDate": "string", "Description": "string", "LayerVersionArn": "string", "LicenseInfo": "string", "Version": number }, "LayerArn": "string", "LayerName": "string" } ], "NextMarker": "string" } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListLayers.md
e4e89bf31f18-0
If the action is successful, the service sends back an HTTP 200 response\. The following data is returned in JSON format by the service\. ** [Layers](#API_ListLayers_ResponseSyntax) ** <a name="SSS-ListLayers-response-Layers"></a> A list of function layers\. Type: Array of [LayersListItem](API_LayersListItem.md) objects ** [NextMarker](#API_ListLayers_ResponseSyntax) ** <a name="SSS-ListLayers-response-NextMarker"></a> A pagination token returned when the response doesn't contain all layers\. Type: String
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListLayers.md
0caf7cfcc243-0
**InvalidParameterValueException** One of the parameters in the request is invalid\. HTTP Status Code: 400 **ServiceException** The AWS Lambda service encountered an internal error\. HTTP Status Code: 500 **TooManyRequestsException** The request throughput limit was exceeded\. HTTP Status Code: 429
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListLayers.md
a6c84b9267c6-0
For more information about using this API in one of the language\-specific AWS SDKs, see the following: + [AWS Command Line Interface](https://docs.aws.amazon.com/goto/aws-cli/lambda-2015-03-31/ListLayers) + [AWS SDK for \.NET](https://docs.aws.amazon.com/goto/DotNetSDKV3/lambda-2015-03-31/ListLayers) + [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/lambda-2015-03-31/ListLayers) + [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/lambda-2015-03-31/ListLayers) + [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/lambda-2015-03-31/ListLayers) + [AWS SDK for JavaScript](https://docs.aws.amazon.com/goto/AWSJavaScriptSDK/lambda-2015-03-31/ListLayers) + [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/lambda-2015-03-31/ListLayers)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListLayers.md
a6c84b9267c6-1
+ [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/lambda-2015-03-31/ListLayers) + [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/lambda-2015-03-31/ListLayers)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListLayers.md
c287dd11345e-0
The first time you invoke your function, AWS Lambda creates an instance of the function and runs its handler method to process the event\. When the function returns a response, it stays active and waits to process additional events\. If you invoke the function again while the first event is being processed, Lambda initializes another instance, and the function processes the two events concurrently\. As more events come in, Lambda routes them to available instances and creates new instances as needed\. When the number of requests decreases, Lambda stops unused instances to free up scaling capacity for other functions\. Your functions' *concurrency* is the number of instances that serve requests at a given time\. For an initial burst of traffic, your functions' cumulative concurrency in a Region can reach an initial level of between 500 and 3000, which varies per Region\. **Burst concurrency quotas** + **3000** – US West \(Oregon\), US East \(N\. Virginia\), Europe \(Ireland\) + **1000** – Asia Pacific \(Tokyo\), Europe \(Frankfurt\), US East \(Ohio\) + **500** – Other Regions After the initial burst, your functions' concurrency can scale by an additional 500 instances each minute\. This continues until there are enough instances to serve all requests, or until a concurrency limit is reached\. When requests come in faster than your function can scale, or when your function is at maximum concurrency, additional requests fail with a throttling error \(429 status code\)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-scaling.md
c287dd11345e-1
The following example shows a function processing a spike in traffic\. As invocations increase exponentially, the function scales up\. It initializes a new instance for any request that can't be routed to an available instance\. When the burst concurrency limit is reached, the function starts to scale linearly\. If this isn't enough concurrency to serve all requests, additional requests are throttled and should be retried\. ![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling.png) **Legend** + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.instances.png) Function instances + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.open.png) Open requests + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling.throttling.png) Throttling possible The function continues to scale until the account's concurrency limit for the function's Region is reached\. The function catches up to demand, requests subside, and unused instances of the function are stopped after being idle for some time\. Unused instances are frozen while they're waiting for requests and don't incur any charges\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-scaling.md
c287dd11345e-2
The regional concurrency limit starts at 1,000\. You can increase the limit by submitting a request in the [Support Center console](https://console.aws.amazon.com/support/v1#/case/create?issueType=service-limit-increase)\. To allocate capacity on a per\-function basis, you can configure functions with [reserved concurrency](configuration-concurrency.md)\. Reserved concurrency creates a pool that can only be used by its function, and also prevents its function from using unreserved concurrency\. When your function scales up, the first request served by each instance is impacted by the time it takes to load and initialize your code\. If your [initialization code](gettingstarted-features.md#gettingstarted-features-programmingmodel) takes a long time, the impact on average and percentile latency can be significant\. To enable your function to scale without fluctuations in latency, use [provisioned concurrency](configuration-concurrency.md)\. The following example shows a function with provisioned concurrency processing a spike in traffic\. ![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.png) **Legend** + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.instances.png) Function instances
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-scaling.md
c287dd11345e-3
+ ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.open.png) Open requests + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.provisioned.png) Provisioned concurrency + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.standard.png) Standard concurrency When you allocate provisioned concurrency, your function is ready to serve a burst of incoming requests with very low latency\. When all provisioned concurrency is in use, the function scales up normally to handle any additional requests\. Application Auto Scaling takes this a step further by providing autoscaling for provisioned concurrency\. With Application Auto Scaling, you can create a target tracking scaling policy that adjusts provisioned concurrency levels automatically, based on the utilization metric that Lambda emits\. [Use the Application Auto Scaling API](configuration-concurrency.md#configuration-concurrency-api) to register an alias as a scalable target and create a scaling policy\. In the following example, a function scales between a minimum and maximum amount of provisioned concurrency based on utilization\. When the number of open requests increases, Application Auto Scaling increases provisioned concurrency in large steps until it reaches the configured maximum\. The function continues to scale on standard concurrency until utilization starts to drop\. When utilization is consistently low, Application Auto Scaling decreases provisioned concurrency in smaller periodic steps\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-scaling.md
c287dd11345e-4
![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned-auto.png) **Legend** + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.instances.png) Function instances + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.open.png) Open requests + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.provisioned.png) Provisioned concurrency + ![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-scaling-provisioned.standard.png) Standard concurrency When you invoke your function asynchronously, by using an event source mapping or another AWS service, scaling behavior varies\. For example, event source mappings that read from a stream are limited by the number of shards in the stream\. Scaling capacity that is unused by an event source is available for use by other clients and event sources\. For more information, see the following topics\. + [Asynchronous invocation](invocation-async.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-scaling.md