id
stringlengths
14
16
text
stringlengths
1
2.43k
source
stringlengths
99
229
027313e87b90-0
**Path** – `/runtime/init/error` **Method** – **POST** If the runtime encounters an error during initialization, it posts an error message to the initialization error path\. **Example initialization error request** ``` ERROR="{\"errorMessage\" : \"Failed to load function.\", \"errorType\" : \"InvalidFunctionException\"}" curl -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/init/error" -d "$ERROR" --header "Lambda-Runtime-Function-Error-Type: Unhandled" ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/runtimes-api.md
cca4d3f133c3-0
You can use a Lambda function to process Amazon Simple Notification Service notifications\. Amazon SNS supports Lambda functions as a target for messages sent to a topic\. You can subscribe your function to topics in the same account or in other AWS accounts\. Amazon SNS invokes your function [asynchronously](invocation-async.md) with an event that contains a message and metadata\. **Example Amazon SNS message event** ``` { "Records": [ { "EventVersion": "1.0", "EventSubscriptionArn": "arn:aws:sns:us-east-2:123456789012:sns-lambda:21be56ed-a058-49f5-8c98-aedd2564c486", "EventSource": "aws:sns", "Sns": { "SignatureVersion": "1", "Timestamp": "2019-01-02T12:45:07.000Z", "Signature": "tcc6faL2yUC6dgZdmrwh1Y4cGa/ebXEkAi6RibDsvpi+tE/1+82j...65r==",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-sns.md
cca4d3f133c3-1
"SigningCertUrl": "https://sns.us-east-2.amazonaws.com/SimpleNotificationService-ac565b8b1a6c5d002d285f9598aa1d9b.pem", "MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e", "Message": "Hello from SNS!", "MessageAttributes": { "Test": { "Type": "String", "Value": "TestString" }, "TestBinary": { "Type": "Binary", "Value": "TestBinary" } }, "Type": "Notification", "UnsubscribeUrl": "https://sns.us-east-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-2:123456789012:test-lambda:21be56ed-a058-49f5-8c98-aedd2564c486", "TopicArn":"arn:aws:sns:us-east-2:123456789012:sns-lambda", "Subject": "TestInvoke" }
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-sns.md
cca4d3f133c3-2
"Subject": "TestInvoke" } } ] } ``` For asynchronous invocation, Lambda queues the message and handles retries\. If Amazon SNS is unable to reach Lambda or the message is rejected, Amazon SNS retries at increasing intervals over several hours\. For details, see [Reliability](https://aws.amazon.com/sns/faqs/#Reliability) in the Amazon SNS FAQ\. In order to perform cross account Amazon SNS deliveries to Lambda, you need to authorize your Lambda function to be invoked from Amazon SNS\. In turn, Amazon SNS needs to allow the Lambda account to subscribe to the Amazon SNS topic\. For example, if the Amazon SNS topic is in account A and the Lambda function is in account B, both accounts must grant permissions to the other to access their respective resources\. Since not all the options for setting up cross\-account permissions are available from the AWS console, you use the AWS CLI to set up the entire process\. For more information, see [Invoking Lambda functions using Amazon SNS notifications](https://docs.aws.amazon.com/sns/latest/dg/sns-lambda.html) in the *Amazon Simple Notification Service Developer Guide*\. **Topics** + [Tutorial: Using AWS Lambda with Amazon Simple Notification Service](with-sns-example.md) + [Sample function code](with-sns-create-package.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-sns.md
7d160fd2b063-0
You can run JavaScript code with Node\.js in AWS Lambda\. Lambda provides [runtimes](lambda-runtimes.md) for Node\.js that execute your code to process events\. Your code runs in an environment that includes the AWS SDK for JavaScript, with credentials from an AWS Identity and Access Management \(IAM\) role that you manage\. Lambda supports the following Node\.js runtimes\. **Node\.js runtimes** | Name | Identifier | AWS SDK for JavaScript | Operating system | | --- | --- | --- | --- | | Node\.js 12 | `nodejs12.x` | 2\.712\.0 | Amazon Linux 2 | | Node\.js 10 | `nodejs10.x` | 2\.712\.0 | Amazon Linux 2 | Lambda functions use an [execution role](lambda-intro-execution-role.md) to get permission to write logs to Amazon CloudWatch Logs, and to access other services and resources\. If you don't already have an execution role for function development, create one\. **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** – **Lambda**\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-nodejs.md
7d160fd2b063-1
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\. You can add permissions to the role later, or swap it out for a different role that's specific to a single function\. **To create a Node\.js function** 1. Open the [Lambda console](https://console.aws.amazon.com/lambda)\. 1. Choose **Create function**\. 1. Configure the following settings: + **Name** – **my\-function**\. + **Runtime** – **Node\.js 12\.x**\. + **Role** – **Choose an existing role**\. + **Existing role** – **lambda\-role**\. 1. Choose **Create function**\. 1. To configure a test event, choose **Test**\. 1. For **Event name**, enter **test**\. 1. Choose **Create**\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-nodejs.md
7d160fd2b063-2
1. For **Event name**, enter **test**\. 1. Choose **Create**\. 1. To execute the function, choose **Test**\. The console creates a Lambda function with a single source file named `index.js`\. You can edit this file and add more files in the built\-in [code editor](code-editor.md)\. To save your changes, choose **Save**\. Then, to run your code, choose **Test**\. **Note** The Lambda console uses AWS Cloud9 to provide an integrated development environment in the browser\. You can also use AWS Cloud9 to develop Lambda functions in your own environment\. For more information, see [Working with AWS Lambda Functions](https://docs.aws.amazon.com/cloud9/latest/user-guide/lambda-functions.html) in the AWS Cloud9 user guide\. The `index.js` file exports a function named `handler` that takes an event object and a context object\. This is the [handler function](nodejs-handler.md) that Lambda calls when the function is invoked\. The Node\.js function runtime gets invocation events from Lambda and passes them to the handler\. In the function configuration, the handler value is `index.handler`\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-nodejs.md
7d160fd2b063-3
Each time you save your function code, the Lambda console creates a deployment package, which is a ZIP archive that contains your function code\. As your function development progresses, you will want to store your function code in source control, add libraries, and automate deployments\. Start by [creating a deployment package](nodejs-package.md) and updating your code at the command line\. **Note** To get started with application development in your local environment, deploy one of the sample applications available in this guide's GitHub repository\. [blank\-nodejs](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-nodejs) – A Node\.js function that shows the use of logging, environment variables, AWS X\-Ray tracing, layers, unit tests and the AWS SDK\. [nodejs\-apig](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/nodejs-apig) – A function with a public API endpoint that processes an event from API Gateway and returns an HTTP response\. [rds\-mysql](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/rds-mysql) – A function that relays queries to a MySQL for RDS Database\. This sample includes a private VPC and database instance configured with a password in AWS Secrets Manager\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-nodejs.md
7d160fd2b063-4
[efs\-nodejs](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/efs-nodejs) – A function that uses an Amazon EFS file system in a Amazon VPC\. This sample includes a VPC, file system, mount targets, and access point configured for use with Lambda\. [list\-manager](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/list-manager) – A function processes events from an Amazon Kinesis data stream and update aggregate lists in Amazon DynamoDB\. The function stores a record of each event in a MySQL for RDS Database in a private VPC\. This sample includes a private VPC with a VPC endpoint for DynamoDB and a database instance\. [error\-processor](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/error-processor) – A Node\.js function generates errors for a specified percentage of requests\. A CloudWatch Logs subscription invokes a second function when an error is recorded\. The processor function uses the AWS SDK to gather details about the request and stores them in an Amazon S3 bucket\. The function runtime passes a context object to the handler, in addition to the invocation event\. The [context object](nodejs-context.md) contains additional information about the invocation, the function, and the execution environment\. More information is available from environment variables\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-nodejs.md
7d160fd2b063-5
Your Lambda function comes with a CloudWatch Logs log group\. The function runtime sends details about each invocation to CloudWatch Logs\. It relays any [logs that your function outputs](nodejs-logging.md) during invocation\. If your function [returns an error](nodejs-exceptions.md), Lambda formats the error and returns it to the invoker\. **Topics** + [AWS Lambda function handler in Node\.js](nodejs-handler.md) + [AWS Lambda deployment package in Node\.js](nodejs-package.md) + [AWS Lambda context object in Node\.js](nodejs-context.md) + [AWS Lambda function logging in Node\.js](nodejs-logging.md) + [AWS Lambda function errors in Node\.js](nodejs-exceptions.md) + [Instrumenting Node\.js code in AWS Lambda](nodejs-tracing.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-nodejs.md
3ea8634da089-0
Your Lambda function comes with a CloudWatch Logs log group, with a log stream for each instance of your function\. The runtime sends details about each invocation to the log stream, and relays logs and other output from your function's code\. To output logs from your function code, you can use methods on [java\.lang\.System](https://docs.oracle.com/javase/8/docs/api/java/lang/System.html), or any logging module that writes to `stdout` or `stderr`\. The [aws\-lambda\-java\-core](java-package.md) library provides a logger class named `LambdaLogger` that you can access from the context object\. The logger class supports multiline logs\. The following example uses the `LambdaLogger` logger provided by the context object\. **Example Handler\.java** ``` // Handler value: example.Handler public class Handler implements RequestHandler<Object, String>{ Gson gson = new GsonBuilder().setPrettyPrinting().create(); @Override public String handleRequest(Object event, Context context) { LambdaLogger logger = context.getLogger(); String response = new String("SUCCESS"); // log execution details logger.log("ENVIRONMENT VARIABLES: " + gson.toJson(System.getenv()));
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
3ea8634da089-1
// log execution details logger.log("ENVIRONMENT VARIABLES: " + gson.toJson(System.getenv())); logger.log("CONTEXT: " + gson.toJson(context)); // process event logger.log("EVENT: " + gson.toJson(event)); return response; } } ``` **Example log format** ``` START RequestId: 6bc28136-xmpl-4365-b021-0ce6b2e64ab0 Version: $LATEST ENVIRONMENT VARIABLES: { "_HANDLER": "example.Handler", "AWS_EXECUTION_ENV": "AWS_Lambda_java8", "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "512", ... } CONTEXT: { "memoryLimit": 512, "awsRequestId": "6bc28136-xmpl-4365-b021-0ce6b2e64ab0", "functionName": "java-console", ... } EVENT: { "records": [ {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
3ea8634da089-2
... } EVENT: { "records": [ { "messageId": "19dd0b57-xmpl-4ac1-bd88-01bbb068cb78", "receiptHandle": "MessageReceiptHandle", "body": "Hello from SQS!", ... } ] } END RequestId: 6bc28136-xmpl-4365-b021-0ce6b2e64ab0 REPORT RequestId: 6bc28136-xmpl-4365-b021-0ce6b2e64ab0 Duration: 198.50 ms Billed Duration: 200 ms Memory Size: 512 MB Max Memory Used: 90 MB Init Duration: 524.75 ms ``` The Java runtime logs the `START`, `END`, and `REPORT` lines for each invocation\. The report line provides the following details: **Report Log** + **RequestId** – The unique request ID for the invocation\. + **Duration** – The amount of time that your function's handler method spent processing the event\. + **Billed Duration** – The amount of time billed for the invocation\. + **Memory Size** – The amount of memory allocated to the function\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
3ea8634da089-3
+ **Memory Size** – The amount of memory allocated to the function\. + **Max Memory Used** – The amount of memory used by the function\. + **Init Duration** – For the first request served, the amount of time it took the runtime to load the function and run code outside of the handler method\. + **XRAY TraceId** – For traced requests, the [AWS X\-Ray trace ID](services-xray.md)\. + **SegmentId** – For traced requests, the X\-Ray segment ID\. + **Sampled** – For traced requests, the sampling result\. You can view logs in the Lambda console, in the CloudWatch Logs console, or from the command line\. **Topics** + [Viewing logs in the AWS Management Console](#java-logging-console) + [Using the AWS CLI](#java-logging-cli) + [Deleting logs](#java-logging-delete) + [Advanced logging with Log4j 2 and SLF4J](#java-logging-log4j2) + [Sample logging code](#java-logging-samples)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
637c22d865e3-0
The Lambda console shows log output when you test a function on the function configuration page\. To view logs for all invocations, use the CloudWatch Logs console\. **To view your Lambda function's logs** 1. Open the [Logs page of the CloudWatch console](https://console.aws.amazon.com/cloudwatch/home?#logs:)\. 1. Choose the log group for your function \(**/aws/lambda/*function\-name***\)\. 1. Choose the first stream in the list\. Each log stream corresponds to an [instance of your function](runtimes-context.md)\. New streams appear when you update your function and when additional instances are created to handle multiple concurrent invocations\. To find logs for specific invocations, you can instrument your function with X\-Ray, and record details about the request and log stream in the trace\. For a sample application that correlates logs and traces with X\-Ray, see [Error processor sample application for AWS Lambda](samples-errorprocessor.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
1717883f4076-0
To get logs for an invocation from the command line, use the `--log-type` option\. The response includes a `LogResult` field that contains up to 4 KB of base64\-encoded logs from the invocation\. ``` $ aws lambda invoke --function-name my-function out --log-type Tail { "StatusCode": 200, "LogResult": "U1RBUlQgUmVxdWVzdElkOiA4N2QwNDRiOC1mMTU0LTExZTgtOGNkYS0yOTc0YzVlNGZiMjEgVmVyc2lvb...", "ExecutedVersion": "$LATEST" } ``` You can use the `base64` utility to decode the logs\. ``` $ aws lambda invoke --function-name my-function out --log-type Tail \ --query 'LogResult' --output text | base64 -d START RequestId: 57f231fb-1730-4395-85cb-4f71bd2b87b8 Version: $LATEST
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
1717883f4076-1
START RequestId: 57f231fb-1730-4395-85cb-4f71bd2b87b8 Version: $LATEST "AWS_SESSION_TOKEN": "AgoJb3JpZ2luX2VjELj...", "_X_AMZN_TRACE_ID": "Root=1-5d02e5ca-f5792818b6fe8368e5b51d50;Parent=191db58857df8395;Sampled=0"",ask/lib:/opt/lib", END RequestId: 57f231fb-1730-4395-85cb-4f71bd2b87b8 REPORT RequestId: 57f231fb-1730-4395-85cb-4f71bd2b87b8 Duration: 79.67 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 73 MB ``` The `base64` utility is available on Linux, macOS, and [Ubuntu on Windows](https://docs.microsoft.com/en-us/windows/wsl/install-win10)\. For macOS, the command is `base64 -D`\. To get full log events from the command line, you can include the log stream name in the output of your function, as shown in the preceding example\. The following example script invokes a function named `my-function` and downloads the last five log events\. **Example get\-logs\.sh Script**
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
1717883f4076-2
**Example get\-logs\.sh Script** This example requires that `my-function` returns a log stream ID\. ``` #!/bin/bash aws lambda invoke --function-name my-function --payload '{"key": "value"}' out sed -i'' -e 's/"//g' out sleep 15 aws logs get-log-events --log-group-name /aws/lambda/my-function --log-stream-name $(cat out) --limit 5 ``` The script uses `sed` to remove quotes from the output file, and sleeps for 15 seconds to allow time for the logs to be available\. The output includes the response from Lambda and the output from the `get-log-events` command\. ``` $ ./get-logs.sh { "StatusCode": 200, "ExecutedVersion": "$LATEST" } { "events": [ { "timestamp": 1559763003171, "message": "START RequestId: 4ce9340a-b765-490f-ad8a-02ab3415e2bf Version: $LATEST\n", "ingestionTime": 1559763003309 }, {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
1717883f4076-3
"ingestionTime": 1559763003309 }, { "timestamp": 1559763003173, "message": "2019-06-05T19:30:03.173Z\t4ce9340a-b765-490f-ad8a-02ab3415e2bf\tINFO\tENVIRONMENT VARIABLES\r{\r \"AWS_LAMBDA_FUNCTION_VERSION\": \"$LATEST\",\r ...", "ingestionTime": 1559763018353 }, { "timestamp": 1559763003173, "message": "2019-06-05T19:30:03.173Z\t4ce9340a-b765-490f-ad8a-02ab3415e2bf\tINFO\tEVENT\r{\r \"key\": \"value\"\r}\n", "ingestionTime": 1559763018353 }, { "timestamp": 1559763003218, "message": "END RequestId: 4ce9340a-b765-490f-ad8a-02ab3415e2bf\n", "ingestionTime": 1559763018353 }, {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
1717883f4076-4
"ingestionTime": 1559763018353 }, { "timestamp": 1559763003218, "message": "REPORT RequestId: 4ce9340a-b765-490f-ad8a-02ab3415e2bf\tDuration: 26.73 ms\tBilled Duration: 100 ms \tMemory Size: 128 MB\tMax Memory Used: 75 MB\t\n", "ingestionTime": 1559763018353 } ], "nextForwardToken": "f/34783877304859518393868359594929986069206639495374241795", "nextBackwardToken": "b/34783877303811383369537420289090800615709599058929582080" } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
a82f9f9b1aeb-0
Log groups aren't deleted automatically when you delete a function\. To avoid storing logs indefinitely, delete the log group, or [configure a retention period](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html#SettingLogRetention) after which logs are deleted automatically\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
cd8fbe23d9ff-0
To customize log output, support logging during unit tests, and log AWS SDK calls, use Apache Log4j 2 with SLF4J\. Log4j is a logging library for Java programs that enables you to configure log levels and use appender libraries\. SLF4J is a facade library that lets you change which library you use without changing your function code\. To add the request ID to your function's logs, use the appender in the [aws\-lambda\-java\-log4j2](java-package.md) library\. The following example shows a Log4j 2 configuration file that adds a timestamp and request ID to all logs\. **Example [src/main/resources/log4j2\.xml](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/blank-java/src/main/resources/log4j2.xml) – Appender configuration** ``` <Configuration status="WARN"> <Appenders> <Lambda name="Lambda"> <PatternLayout> <pattern>%d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1} - %m%n</pattern> </PatternLayout> </Lambda> </Appenders> <Loggers> <Root level="INFO">
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
cd8fbe23d9ff-1
</Lambda> </Appenders> <Loggers> <Root level="INFO"> <AppenderRef ref="Lambda"/> </Root> <Logger name="software.amazon.awssdk" level="WARN" /> <Logger name="software.amazon.awssdk.request" level="DEBUG" /> </Loggers> </Configuration> ``` With this configuration, each line is prepended with the date, time, request ID, log level, and class name\. **Example log format with appender** ``` START RequestId: 6bc28136-xmpl-4365-b021-0ce6b2e64ab0 Version: $LATEST 2020-03-18 08:52:43 6bc28136-xmpl-4365-b021-0ce6b2e64ab0 INFO Handler - ENVIRONMENT VARIABLES: { "_HANDLER": "example.Handler", "AWS_EXECUTION_ENV": "AWS_Lambda_java8", "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "512", ... } 2020-03-18 08:52:43 6bc28136-xmpl-4365-b021-0ce6b2e64ab0 INFO Handler - CONTEXT:
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
cd8fbe23d9ff-2
{ "memoryLimit": 512, "awsRequestId": "6bc28136-xmpl-4365-b021-0ce6b2e64ab0", "functionName": "java-console", ... } ``` SLF4J is a facade library for logging in Java code\. In your function code, you use the SLF4J logger factory to retrieve a logger with methods for log levels like `info()` and `warn()`\. In your build configuration, you include the logging library and SLF4J adapter in the classpath\. By changing the libraries in the build configuration, you can change the logger type without changing your function code\. SLF4J is required to capture logs from the SDK for Java\. In the following example, the handler class uses SLF4J to retrieve a logger\. **Example [src/main/java/example/Handler\.java](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/blank-java/src/main/java/example/Handler.java) – Logging with SLF4J** ``` import org.slf4j.Logger; import org.slf4j.LoggerFactory; // Handler value: example.Handler public class Handler implements RequestHandler<SQSEvent, String>{
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
cd8fbe23d9ff-3
// Handler value: example.Handler public class Handler implements RequestHandler<SQSEvent, String>{ private static final Logger logger = LoggerFactory.getLogger(Handler.class); Gson gson = new GsonBuilder().setPrettyPrinting().create(); LambdaAsyncClient lambdaClient = LambdaAsyncClient.create(); @Override public String handleRequest(SQSEvent event, Context context) { String response = new String(); // call Lambda API logger.info("Getting account settings"); CompletableFuture<GetAccountSettingsResponse> accountSettings = lambdaClient.getAccountSettings(GetAccountSettingsRequest.builder().build()); // log execution details logger.info("ENVIRONMENT VARIABLES: {}", gson.toJson(System.getenv())); ... ``` The build configuration takes runtime dependencies on the Lambda appender and SLF4J adapter, and implementation dependencies on Log4J 2\. **Example [build\.gradle](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/blank-java/build.gradle) – Logging dependencies**
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
cd8fbe23d9ff-4
``` dependencies { implementation platform('software.amazon.awssdk:bom:2.10.73') implementation platform('com.amazonaws:aws-xray-recorder-sdk-bom:2.4.0') implementation 'software.amazon.awssdk:lambda' implementation 'com.amazonaws:aws-xray-recorder-sdk-core' implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-core' implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-v2' implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-v2-instrumentor' implementation 'com.amazonaws:aws-lambda-java-core:1.2.1' implementation 'com.amazonaws:aws-lambda-java-events:3.1.0' implementation 'com.google.code.gson:gson:2.8.6' implementation 'org.apache.logging.log4j:log4j-api:2.13.0' implementation 'org.apache.logging.log4j:log4j-core:2.13.0' runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.13.0'
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
cd8fbe23d9ff-5
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.13.0' runtimeOnly 'com.amazonaws:aws-lambda-java-log4j2:1.2.0' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0' } ``` When you run your code locally for tests, the context object with the Lambda logger is not available, and there's no request ID for the Lambda appender to use\. For example test configurations, see the sample applications in the next section\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
c3a513682a2b-0
The GitHub repository for this guide includes sample applications that demonstrate the use of various logging configurations\. Each sample application includes scripts for easy deployment and cleanup, an AWS SAM template, and supporting resources\. **Sample Lambda applications in Java** + [blank\-java](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-java) – A Java function that shows the use of Lambda's Java libraries, logging, environment variables, layers, AWS X\-Ray tracing, unit tests, and the AWS SDK\. + [java\-basic](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/java-basic) – A minimal Java function with unit tests and variable logging configuration\. + [java\-events](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/java-events) – A minimal Java function that uses the [aws\-lambda\-java\-events](java-package.md) library with event types that don't require the AWS SDK as a dependency, such as Amazon API Gateway\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
c3a513682a2b-1
+ [java\-events\-v1sdk](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/java-events-v1sdk) – A Java function that uses the [aws\-lambda\-java\-events](java-package.md) library with event types that require the AWS SDK as a dependency \(Amazon Simple Storage Service, Amazon DynamoDB, and Amazon Kinesis\)\. + [s3\-java](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/s3-java) – A Java function that processes notification events from Amazon S3 and uses the Java Class Library \(JCL\) to create thumbnails from uploaded image files\. The `java-basic` sample application shows a minimal logging configuration that supports logging tests\. The handler code uses the `LambdaLogger` logger provided by the context object\. For tests, the application uses a custom `TestLogger` class that implements the `LambdaLogger` interface with a Log4j 2 logger\. It uses SLF4J as a facade for compatibility with the AWS SDK\. Logging libraries are excluded from build output to keep the deployment package small\. The `blank-java` sample application builds on the basic configuration with AWS SDK logging and the Lambda Log4j 2 appender\. It uses Log4j 2 in Lambda with custom appender that adds the invocation request ID to each line\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-logging.md
be2939a60e5f-0
In this tutorial you will use the Lambda console to create a Lambda function, and an Amazon API Gateway endpoint to trigger that function\. You will be able to call the endpoint with any method \(`GET`, `POST`, `PATCH`, etc\.\) to trigger your Lambda function\. When the endpoint is called, the entire request will be passed through to your Lambda function\. Your function action will depend on the method you call your endpoint with: + DELETE: delete an item from a DynamoDB table + GET: scan table and return all items + POST: Create an item + PUT: Update an item
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-apigateway-blueprint.md
f3cb23fb79bf-0
Follow the steps in this section to create a new Lambda function and an API Gateway endpoint to trigger it: **To create an API** 1. Sign in to the AWS Management Console and open the AWS Lambda console\. 1. Choose **Create Lambda function**\. 1. Choose **Blueprint**\. 1. Enter **microservice** in the search bar\. Choose the **microservice\-http\-endpoint** blueprint and then choose **Configure**\. 1. Configure the following settings\. + **Name** – **lambda\-microservice**\. + **Role** – **Create a new role from one or more templates**\. + **Role name** – **lambda\-apigateway\-role**\. + **Policy templates** – **Simple microservice permissions**\. + **API** – **Create a new API**\. + **Security** – **Open**\. Choose **Create function**\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-apigateway-blueprint.md
f3cb23fb79bf-1
+ **Security** – **Open**\. Choose **Create function**\. When you complete the wizard and create your function, Lambda creates a proxy resource named `lambda-microservice` under the API name you selected\. For more information about proxy resources, see [Configure proxy integration for a proxy resource](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html)\. A proxy resource has an `AWS_PROXY` integration type and a catch\-all method `ANY`\. The `AWS_PROXY` integration type applies a default mapping template to pass through the entire request to the Lambda function and transforms the output from the Lambda function to HTTP responses\. The `ANY` method defines the same integration setup for all the supported methods, including `GET`, `POST`, `PATCH`, `DELETE `and others\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-apigateway-blueprint.md
9ed5f14fc71f-0
In this step, you will use the console to test the Lambda function\. In addition, you can run a `curl` command to test the end\-to\-end experience\. That is, send an HTTPS request to your API method and have Amazon API Gateway invoke your Lambda function\. In order to complete the steps, make sure you have created a DynamoDB table and named it "MyTable"\. For more information, see [Create a DynamoDB table with a stream enabled](with-ddb-example.md#with-ddb-create-buckets) **To test the API** 1. With your `MyLambdaMicroService` function still open in the console, choose the **Actions** tab and then choose **Configure test event**\. 1. Replace the existing text with the following: ``` { "httpMethod": "GET", "queryStringParameters": { "TableName": "MyTable" } } ``` 1. After entering the text above choose **Save and test**\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-apigateway-blueprint.md
c0039bc22f2d-0
To set up your development environment for writing PowerShell scripts, do the following: 1. **Install the correct version of PowerShell** – Lambda's support for PowerShell is based on the cross\-platform PowerShell Core 6\.0 release\. This means that you can develop your PowerShell Lambda functions on Windows, Linux, or Mac\. If you don’t have this version of PowerShell installed, you can find instructions in [Installing PowerShell Core](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell#powershell-core)\. 1. **Install the \.NET Core 3\.1 SDK** – Because PowerShell Core is built on top of \.NET Core, the Lambda support for PowerShell uses the same \.NET Core 3\.1 Lambda runtime for both \.NET Core and PowerShell Lambda functions\. The \.NET Core 3\.1 SDK is used by the new Lambda PowerShell publishing cmdlets to create the Lambda deployment package\. The \.NET Core 3\.1 SDK is available at [\.NET downloads](https://www.microsoft.com/net/download) on the Microsoft website\. Be sure to install the SDK and not the runtime installation\. 1. **Install the AWSLambdaPSCore module** – You can install this either from the [ PowerShell Gallery](https://www.powershellgallery.com/packages/AWSLambdaPSCore), or you can install it by using the following PowerShell Core shell command: ``` Install-Module AWSLambdaPSCore -Scope CurrentUser
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/powershell-devenv.md
c0039bc22f2d-1
``` Install-Module AWSLambdaPSCore -Scope CurrentUser ``` 1. **\(Optional\) Install AWS Tools for PowerShell** – You can install either the modularized [AWS\.Tools](https://docs.aws.amazon.com/powershell/latest/userguide/pstools-welcome.html#pwsh_structure_pstools) or single\-module [AWSPowerShell\.NetCore](https://docs.aws.amazon.com/powershell/latest/userguide/pstools-welcome.html#pwsh_structure_pscore) version in PowerShell Core 6\.0 to use the Lambda API within your PowerShell environment\\\. For instructions, see [Installing the AWS Tools for PowerShell](https://docs.aws.amazon.com/powershell/latest/userguide/pstools-getting-set-up.html)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/powershell-devenv.md
6d0344580fb8-0
AWS Lambda integrates with other AWS services to invoke functions\. You can configure triggers to invoke a function in response to resource lifecycle events, respond to incoming HTTP requests, consume events from a queue, or [run on a schedule](services-cloudwatchevents.md)\. Each service that integrates with Lambda sends data to your function in JSON as an event\. The structure of the event document is different for each event type, and contains data about the resource or request that triggered the function\. Lambda runtimes convert the event into an object and pass it to your function\. The following example shows a test event from an [Application Load Balancer](services-alb.md) that represents a GET request to `/lambda?query=1234ABCD`\. **Example event from an Application Load Balancer** ``` { "requestContext": { "elb": { "targetGroupArn": "arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/lambda-279XGJDqGZ5rsrHC2Fjr/49e9d65c45c6791a" } }, "httpMethod": "GET", "path": "/lambda", "queryStringParameters": { "query": "1234ABCD" }, "headers": {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-services.md
6d0344580fb8-1
"query": "1234ABCD" }, "headers": { "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "accept-encoding": "gzip", "accept-language": "en-US,en;q=0.9", "connection": "keep-alive", "host": "lambda-alb-123578498.us-east-2.elb.amazonaws.com", "upgrade-insecure-requests": "1", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36", "x-amzn-trace-id": "Root=1-5c536348-3d683b8b04734faae651f476", "x-forwarded-for": "72.12.164.125", "x-forwarded-port": "80", "x-forwarded-proto": "http", "x-imforwards": "20" }, "body": "",
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-services.md
6d0344580fb8-2
"x-imforwards": "20" }, "body": "", "isBase64Encoded": false } ``` **Note** The Lambda runtime converts the event document into an object and passes it to your [function handler](gettingstarted-concepts.md)\. For compiled languages, Lambda provides definitions for event types in a library\. See the following topics for more information\. [Building Lambda functions with Java](lambda-java.md) [Building Lambda functions with Go](lambda-golang.md) [Building Lambda functions with C\#](lambda-csharp.md) [Building Lambda functions with PowerShell](lambda-powershell.md) For services that generate a queue or data stream, you create an [event source mapping](invocation-eventsourcemapping.md) in Lambda and grant Lambda permission to access the other service in the [execution role](lambda-intro-execution-role.md)\. Lambda reads data from the other service, creates an event, and invokes your function\. **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)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-services.md
6d0344580fb8-3
+ [Amazon Managed Streaming for Apache Kafka](with-msk.md) + [Amazon Simple Queue Service](with-sqs.md) Other services invoke your function directly\. You grant the other service permission in the function's [resource\-based policy](access-control-resource-based.md), and configure the other service to generate events and invoke your function\. Depending on the service, the invocation can be synchronous or asynchronous\. For synchronous invocation, the other service waits for the response from your function and might [retry on errors](invocation-retries.md)\. **Services that invoke Lambda functions synchronously** + [Elastic Load Balancing \(Application Load Balancer\)](services-alb.md) + [Amazon Cognito](services-cognito.md) + [Amazon Lex](services-lex.md) + [Amazon Alexa](services-alexa.md) + [Amazon API Gateway](services-apigateway.md) + [Amazon CloudFront \(Lambda@Edge\)](lambda-edge.md) + [Amazon Kinesis Data Firehose](services-kinesisfirehose.md) + [Amazon Simple Storage Service Batch](services-s3-batch.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-services.md
6d0344580fb8-4
+ [Amazon Simple Storage Service Batch](services-s3-batch.md) For asynchronous invocation, Lambda queues the event before passing it to your function\. The other service gets a success response as soon as the event is queued and isn't aware of what happens afterwards\. If an error occurs, Lambda handles [retries](invocation-retries.md), and can send failed events to a [destination](invocation-async.md#invocation-async-destinations) that you configure\. **Services that invoke Lambda functions asynchronously** + [Amazon Simple Storage Service](with-s3.md) + [Amazon Simple Notification Service](with-sns.md) + [Amazon Simple Email Service](services-ses.md) + [AWS CloudFormation](services-cloudformation.md) + [Amazon CloudWatch Logs](services-cloudwatchlogs.md) + [Amazon CloudWatch Events](services-cloudwatchevents.md) + [AWS CodeCommit](services-codecommit.md) + [AWS Config](services-config.md) + [AWS IoT](services-iot.md) + [AWS IoT Events](services-iotevents.md) + [AWS CodePipeline](services-codepipeline.md) Additionally, some services integrate with Lambda in other ways that don't involve invoking functions\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-services.md
6d0344580fb8-5
Additionally, some services integrate with Lambda in other ways that don't involve invoking functions\. **Services that integrate with Lambda in other ways** + [Amazon Elastic File System](services-efs.md) + [AWS X\-Ray](services-xray.md) See the topics in this chapter for more details about each service, and example events that you can use to test your function\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-services.md
be03dfe1f1fa-0
The GitHub repository for this guide includes sample applications that demonstrate the use of various languages and AWS services\. Each sample application includes scripts for easy deployment and cleanup, an AWS SAM template, and supporting resources\. ------
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-samples.md
43b55ca76c57-0
**Sample Lambda applications in Node\.js** + [blank\-nodejs](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-nodejs) – A Node\.js function that shows the use of logging, environment variables, AWS X\-Ray tracing, layers, unit tests and the AWS SDK\. + [nodejs\-apig](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/nodejs-apig) – A function with a public API endpoint that processes an event from API Gateway and returns an HTTP response\. + [rds\-mysql](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/rds-mysql) – A function that relays queries to a MySQL for RDS Database\. This sample includes a private VPC and database instance configured with a password in AWS Secrets Manager\. + [efs\-nodejs](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/efs-nodejs) – A function that uses an Amazon EFS file system in a Amazon VPC\. This sample includes a VPC, file system, mount targets, and access point configured for use with Lambda\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-samples.md
43b55ca76c57-1
+ [list\-manager](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/list-manager) – A function processes events from an Amazon Kinesis data stream and update aggregate lists in Amazon DynamoDB\. The function stores a record of each event in a MySQL for RDS Database in a private VPC\. This sample includes a private VPC with a VPC endpoint for DynamoDB and a database instance\. + [error\-processor](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/error-processor) – A Node\.js function generates errors for a specified percentage of requests\. A CloudWatch Logs subscription invokes a second function when an error is recorded\. The processor function uses the AWS SDK to gather details about the request and stores them in an Amazon S3 bucket\. ------
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-samples.md
e57c7c81e9eb-0
**Sample Lambda applications in Python** + [blank\-python](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-python) – A Python function that shows the use of logging, environment variables, AWS X\-Ray tracing, layers, unit tests and the AWS SDK\. ------
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-samples.md
92710386c027-0
**Sample Lambda applications in Ruby** + [blank\-ruby](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-ruby) – A Ruby function that shows the use of logging, environment variables, AWS X\-Ray tracing, layers, unit tests and the AWS SDK\. ------
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-samples.md
67fd61e31673-0
**Sample Lambda applications in Java** + [blank\-java](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-java) – A Java function that shows the use of Lambda's Java libraries, logging, environment variables, layers, AWS X\-Ray tracing, unit tests, and the AWS SDK\. + [java\-basic](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/java-basic) – A minimal Java function with unit tests and variable logging configuration\. + [java\-events](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/java-events) – A minimal Java function that uses the [aws\-lambda\-java\-events](java-package.md) library with event types that don't require the AWS SDK as a dependency, such as Amazon API Gateway\. + [java\-events\-v1sdk](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/java-events-v1sdk) – A Java function that uses the [aws\-lambda\-java\-events](java-package.md) library with event types that require the AWS SDK as a dependency \(Amazon Simple Storage Service, Amazon DynamoDB, and Amazon Kinesis\)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-samples.md
67fd61e31673-1
+ [s3\-java](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/s3-java) – A Java function that processes notification events from Amazon S3 and uses the Java Class Library \(JCL\) to create thumbnails from uploaded image files\. ------
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-samples.md
93d7f6d475df-0
**Sample Lambda applications in Go** + [blank\-go](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-go) – A Go function that shows the use of Lambda's Go libraries, logging, environment variables, and the AWS SDK\. ------
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-samples.md
94a9b4397fe5-0
**Sample Lambda applications in C\#** + [blank\-csharp](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-csharp) – A C\# function that shows the use of Lambda's \.NET libraries, logging, environment variables, AWS X\-Ray tracing, unit tests, and the AWS SDK\. + [ec2\-spot](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/ec2-spot) – A function that manages spot instance requests in Amazon EC2\. ------
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-samples.md
905382a63a50-0
**Sample Lambda applications in PowerShell** + [blank\-powershell](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-powershell) – A PowerShell function that shows the use of logging, environment variables, and the AWS SDK\. ------ To deploy a sample application, follow the instructions in its README file\. To learn more about the architecture and use cases of an application, read the topics in this chapter\. **Topics** + [Blank function sample application for AWS Lambda](samples-blank.md) + [Error processor sample application for AWS Lambda](samples-errorprocessor.md) + [List manager sample application for AWS Lambda](samples-listmanager.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-samples.md
a5b441c0e661-0
You can build this application using [AWS SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/)\. To learn more about creating AWS SAM templates, see [ AWS SAM template basics](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html) in the *AWS Serverless Application Model Developer Guide*\. Below is a sample AWS SAM template for the Lambda application from the [tutorial](with-sqs-example.md)\. Copy the text below to a \.yaml file and save it next to the ZIP package you created previously\. Note that the `Handler` and `Runtime` parameter values should match the ones you used when you created the function in the previous section\. **Example template\.yaml** ``` AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: Example of processing messages on an SQS queue with Lambda Resources: MySQSQueueFunction: Type: [AWS::Serverless::Function](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html) Properties: Handler: index.handler Runtime: nodejs12.x Events: MySQSEvent: Type: SQS
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-sqs-example-use-app-spec.md
a5b441c0e661-1
Runtime: nodejs12.x Events: MySQSEvent: Type: SQS Properties: Queue: !GetAtt MySqsQueue.Arn BatchSize: 10 MySqsQueue: Type: AWS::SQS::Queue ``` For information on how to package and deploy your serverless application using the package and deploy commands, see [Deploying serverless applications](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-deploying.html) in the *AWS Serverless Application Model Developer Guide*\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-sqs-example-use-app-spec.md
f57b1d33cc7a-0
You can call a Lambda function from a mobile application\. Put business logic in functions to separate its development lifecycle from that of front\-end clients, making mobile applications less complex to develop and maintain\. With the Mobile SDK for Android, you [use Amazon Cognito to authenticate users and authorize requests](with-android-example.md)\. When you invoke a function from a mobile application, you choose the event structure, [invocation type](lambda-invocation.md), and permission model\. You can use [aliases](configuration-aliases.md) to enable seamless updates to your function code, but otherwise the function and application are tightly coupled\. As you add more functions, you can create an API layer to decouple your function code from your front\-end clients and improve performance\. To create a fully\-featured web API for your mobile and web applications, use Amazon API Gateway\. With API Gateway, you can add custom authorizers, throttle requests, and cache results for all of your functions\. For more information, see [Using AWS Lambda with Amazon API Gateway](services-apigateway.md)\. **Topics** + [Tutorial: Using AWS Lambda with the Mobile SDK for Android](with-android-example.md) + [Sample function code](with-android-create-package.md)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-on-demand-custom-android.md
54d869d51071-0
Creates an [alias](https://docs.aws.amazon.com/lambda/latest/dg/versioning-aliases.html) for a Lambda function version\. Use aliases to provide clients with a function identifier that you can update to invoke a different version\. You can also map an alias to split invocation requests between two versions\. Use the `RoutingConfig` parameter to specify a second version and the percentage of invocation requests that it receives\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_CreateAlias.md
80e2f46990bf-0
``` POST /2015-03-31/functions/FunctionName/aliases HTTP/1.1 Content-type: application/json { "Description": "string", "FunctionVersion": "string", "Name": "string", "RoutingConfig": { "AdditionalVersionWeights": { "string" : number } } } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_CreateAlias.md
2c0ca1e35524-0
The request uses the following URI parameters\. ** [FunctionName](#API_CreateAlias_RequestSyntax) ** <a name="SSS-CreateAlias-request-FunctionName"></a> The name of the Lambda function\. **Name formats** + **Function name** \- `MyFunction`\. + **Function ARN** \- `arn:aws:lambda:us-west-2:123456789012:function:MyFunction`\. + **Partial ARN** \- `123456789012:function:MyFunction`\. The length constraint applies only to the full ARN\. If you specify only the function name, it is limited to 64 characters in length\. Length Constraints: Minimum length of 1\. Maximum length of 140\. Pattern: `(arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}(-gov)?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-_]+)(:(\$LATEST|[a-zA-Z0-9-_]+))?` Required: Yes
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_CreateAlias.md
383d9b97a786-0
The request accepts the following data in JSON format\. ** [Description](#API_CreateAlias_RequestSyntax) ** <a name="SSS-CreateAlias-request-Description"></a> A description of the alias\. Type: String Length Constraints: Minimum length of 0\. Maximum length of 256\. Required: No ** [FunctionVersion](#API_CreateAlias_RequestSyntax) ** <a name="SSS-CreateAlias-request-FunctionVersion"></a> The function version that the alias invokes\. Type: String Length Constraints: Minimum length of 1\. Maximum length of 1024\. Pattern: `(\$LATEST|[0-9]+)` Required: Yes ** [Name](#API_CreateAlias_RequestSyntax) ** <a name="SSS-CreateAlias-request-Name"></a> The name of the alias\. Type: String Length Constraints: Minimum length of 1\. Maximum length of 128\. Pattern: `(?!^[0-9]+$)([a-zA-Z0-9-_]+)` Required: Yes ** [RoutingConfig](#API_CreateAlias_RequestSyntax) ** <a name="SSS-CreateAlias-request-RoutingConfig"></a>
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_CreateAlias.md
383d9b97a786-1
The [routing configuration](https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html#configuring-alias-routing) of the alias\. Type: [AliasRoutingConfiguration](API_AliasRoutingConfiguration.md) object Required: No
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_CreateAlias.md
73021e34313d-0
``` HTTP/1.1 201 Content-type: application/json { "AliasArn": "string", "Description": "string", "FunctionVersion": "string", "Name": "string", "RevisionId": "string", "RoutingConfig": { "AdditionalVersionWeights": { "string" : number } } } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_CreateAlias.md
4e662dfb94ea-0
If the action is successful, the service sends back an HTTP 201 response\. The following data is returned in JSON format by the service\. ** [AliasArn](#API_CreateAlias_ResponseSyntax) ** <a name="SSS-CreateAlias-response-AliasArn"></a> The Amazon Resource Name \(ARN\) of the alias\. Type: String Pattern: `arn:(aws[a-zA-Z-]*)?:lambda:[a-z]{2}(-gov)?-[a-z]+-\d{1}:\d{12}:function:[a-zA-Z0-9-_]+(:(\$LATEST|[a-zA-Z0-9-_]+))?` ** [Description](#API_CreateAlias_ResponseSyntax) ** <a name="SSS-CreateAlias-response-Description"></a> A description of the alias\. Type: String Length Constraints: Minimum length of 0\. Maximum length of 256\. ** [FunctionVersion](#API_CreateAlias_ResponseSyntax) ** <a name="SSS-CreateAlias-response-FunctionVersion"></a> The function version that the alias invokes\. Type: String Length Constraints: Minimum length of 1\. Maximum length of 1024\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_CreateAlias.md
4e662dfb94ea-1
The function version that the alias invokes\. Type: String Length Constraints: Minimum length of 1\. Maximum length of 1024\. Pattern: `(\$LATEST|[0-9]+)` ** [Name](#API_CreateAlias_ResponseSyntax) ** <a name="SSS-CreateAlias-response-Name"></a> The name of the alias\. Type: String Length Constraints: Minimum length of 1\. Maximum length of 128\. Pattern: `(?!^[0-9]+$)([a-zA-Z0-9-_]+)` ** [RevisionId](#API_CreateAlias_ResponseSyntax) ** <a name="SSS-CreateAlias-response-RevisionId"></a> A unique identifier that changes when you update the alias\. Type: String ** [RoutingConfig](#API_CreateAlias_ResponseSyntax) ** <a name="SSS-CreateAlias-response-RoutingConfig"></a> The [routing configuration](https://docs.aws.amazon.com/lambda/latest/dg/lambda-traffic-shifting-using-aliases.html) of the alias\. Type: [AliasRoutingConfiguration](API_AliasRoutingConfiguration.md) object
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_CreateAlias.md
bceb974619f8-0
**InvalidParameterValueException** One of the parameters in the request is invalid\. HTTP Status Code: 400 **ResourceConflictException** The resource already exists, or another operation is in progress\. HTTP Status Code: 409 **ResourceNotFoundException** The resource specified in the request does not exist\. HTTP Status Code: 404 **ServiceException** The AWS Lambda service encountered an internal error\. HTTP Status Code: 500 **TooManyRequestsException** The request throughput limit was exceeded\. HTTP Status Code: 429
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_CreateAlias.md
6c80b5568cbb-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/CreateAlias) + [AWS SDK for \.NET](https://docs.aws.amazon.com/goto/DotNetSDKV3/lambda-2015-03-31/CreateAlias) + [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/lambda-2015-03-31/CreateAlias) + [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/lambda-2015-03-31/CreateAlias) + [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/lambda-2015-03-31/CreateAlias) + [AWS SDK for JavaScript](https://docs.aws.amazon.com/goto/AWSJavaScriptSDK/lambda-2015-03-31/CreateAlias) + [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/lambda-2015-03-31/CreateAlias)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_CreateAlias.md
6c80b5568cbb-1
+ [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/lambda-2015-03-31/CreateAlias) + [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/lambda-2015-03-31/CreateAlias)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_CreateAlias.md
4cbdf4a348d4-0
Deletes the provisioned concurrency configuration for a function\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_DeleteProvisionedConcurrencyConfig.md
32f6b9cf72a0-0
``` DELETE /2019-09-30/functions/FunctionName/provisioned-concurrency?Qualifier=Qualifier HTTP/1.1 ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_DeleteProvisionedConcurrencyConfig.md
10020c1fc476-0
The request uses the following URI parameters\. ** [FunctionName](#API_DeleteProvisionedConcurrencyConfig_RequestSyntax) ** <a name="SSS-DeleteProvisionedConcurrencyConfig-request-FunctionName"></a> The name of the Lambda function\. **Name formats** + **Function name** \- `my-function`\. + **Function ARN** \- `arn:aws:lambda:us-west-2:123456789012:function:my-function`\. + **Partial ARN** \- `123456789012:function:my-function`\. The length constraint applies only to the full ARN\. If you specify only the function name, it is limited to 64 characters in length\. Length Constraints: Minimum length of 1\. Maximum length of 140\. Pattern: `(arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}(-gov)?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-_]+)(:(\$LATEST|[a-zA-Z0-9-_]+))?` Required: Yes
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_DeleteProvisionedConcurrencyConfig.md
10020c1fc476-1
Required: Yes ** [Qualifier](#API_DeleteProvisionedConcurrencyConfig_RequestSyntax) ** <a name="SSS-DeleteProvisionedConcurrencyConfig-request-Qualifier"></a> The version number or alias name\. Length Constraints: Minimum length of 1\. Maximum length of 128\. Pattern: `(|[a-zA-Z0-9$_-]+)` Required: Yes
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_DeleteProvisionedConcurrencyConfig.md
081e60e5bc83-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_DeleteProvisionedConcurrencyConfig.md
29259fa4eec7-0
``` HTTP/1.1 204 ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_DeleteProvisionedConcurrencyConfig.md
14a979dadfbc-0
If the action is successful, the service sends back an HTTP 204 response with an empty HTTP body\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_DeleteProvisionedConcurrencyConfig.md
b2f2ebaf13e7-0
**InvalidParameterValueException** One of the parameters in the request is invalid\. HTTP Status Code: 400 **ResourceConflictException** The resource already exists, or another operation is in progress\. HTTP Status Code: 409 **ResourceNotFoundException** The resource specified in the request does not exist\. HTTP Status Code: 404 **ServiceException** The AWS Lambda service encountered an internal error\. HTTP Status Code: 500 **TooManyRequestsException** The request throughput limit was exceeded\. HTTP Status Code: 429
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_DeleteProvisionedConcurrencyConfig.md
de7ecd670447-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/DeleteProvisionedConcurrencyConfig) + [AWS SDK for \.NET](https://docs.aws.amazon.com/goto/DotNetSDKV3/lambda-2015-03-31/DeleteProvisionedConcurrencyConfig) + [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/lambda-2015-03-31/DeleteProvisionedConcurrencyConfig) + [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/lambda-2015-03-31/DeleteProvisionedConcurrencyConfig) + [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/lambda-2015-03-31/DeleteProvisionedConcurrencyConfig) + [AWS SDK for JavaScript](https://docs.aws.amazon.com/goto/AWSJavaScriptSDK/lambda-2015-03-31/DeleteProvisionedConcurrencyConfig)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_DeleteProvisionedConcurrencyConfig.md
de7ecd670447-1
+ [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/lambda-2015-03-31/DeleteProvisionedConcurrencyConfig) + [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/lambda-2015-03-31/DeleteProvisionedConcurrencyConfig) + [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/lambda-2015-03-31/DeleteProvisionedConcurrencyConfig)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_DeleteProvisionedConcurrencyConfig.md
c360e6c5985d-0
AWS IoT Events monitors the inputs from multiple IoT sensors and applications to recognize event patterns\. Then it takes appropriate actions when events occur\. AWS IoT Events receives its inputs as JSON payloads from many sources\. AWS IoT Events supports simple events \(where each input triggers an event\) and complex events \(where multiple inputs must occur to trigger the event\)\. To use AWS IoT Events, you define a detector model, which is a state\-machine model of your equipment or process\. In addition to states, you define inputs and events for the model\. You also define the actions to take when an event occurs\. Use a Lambda function for an action when you want to invoke another AWS service \(such as Amazon Connect\), or take actions in an external application \(such as your enterprise resource planning \(ERP\) application\)\. When the event occurs, AWS IoT Events invokes your Lambda function asynchronously\. It provides information about the detector model and the event that triggered the action\. The following example message event is based on the definitions in the AWS IoT Events [simple step\-by\-step example](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-simple-example.html)\. **Example AWS IoT Events message event** ``` { "event: ":{ "eventName": "myChargedEvent", "eventTime": 1567797571647, "payload":{ "detector":{
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-iotevents.md
c360e6c5985d-1
"eventTime": 1567797571647, "payload":{ "detector":{ "detectorModelName": "AWS_IoTEvents_Hello_World1567793458261", "detectorModelVersion": "4", "keyValue": "100009" }, "eventTriggerDetails":{ "triggerType": "Message", "inputName": "AWS_IoTEvents_HelloWorld_VoltageInput", "messageId": "64c75a34-068b-4a1d-ae58-c16215dc4efd" }, "actionExecutionId": "49f0f32f-1209-38a7-8a76-d6ca49dd0bc4", "state":{ "variables": {}, "stateName": "Charged", "timers": {} } } } } ``` The event that is passed into the Lambda function includes the following fields: + `eventName` – The name for this event in the detector model\. + `eventTime` – The time that the event occurred\. + `detector` – The name and version of the detector model\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-iotevents.md
c360e6c5985d-2
+ `eventTime` – The time that the event occurred\. + `detector` – The name and version of the detector model\. + `eventTriggerDetails` – A description of the input that triggered the event\. + `actionExecutionId` – The unique execution identifier of the action\. + `state` – The state of the detector model when the event occurred\. + `stateName` – The name of the state in the detector model\. + `timers` – Any timers that are set in this state\. + `variables` – Any variable values that are set in this state\. You need to grant permission for the AWS IoT Events service to invoke your Lambda function\. Use the `add-permission` command to add a permission statement to your function's resource\-based policy\. ``` $ aws lambda add-permission --function-name my-function \ --statement-id iot-events --action "lambda:InvokeFunction" --principal iotevents.amazonaws.com {
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-iotevents.md
c360e6c5985d-3
{ "Statement": "{\"Sid\":\"iot-events\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"iotevents.amazonaws.com\"},\"Action\":\"lambda:InvokeFunction\",\"Resource\":\"arn:aws:lambda:us-west-2:123456789012:function:my-function\"}" } ``` For more information about using Lambda with AWS IoT Events, see [Using AWS IoT Events with other services](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-with-others.html)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-iotevents.md
741935dfa862-0
To process events from Amazon Kinesis, iterate through the records included in the event object and decode the Base64\-encoded data included in each\. **Note** The code on this page does not support [aggregated records](https://docs.aws.amazon.com/kinesis/latest/dev/kinesis-kpl-concepts.html#kinesis-kpl-concepts-aggretation)\. You can disable aggregation in the Kinesis Producer Library [configuration](https://docs.aws.amazon.com/kinesis/latest/dev/kinesis-kpl-config.html), or use the [Kinesis Record Aggregation library](https://github.com/awslabs/kinesis-aggregation) to deaggregate records\. Sample code is available for the following languages\. **Topics** + [Node\.js 8](#with-kinesis-example-deployment-pkg-nodejs) + [Java 11](#with-kinesis-example-deployment-pkg-java) + [C\#](#with-kinesis-example-deployment-pkg-dotnet) + [Python 3](#with-kinesis-example-deployment-pkg-python) + [Go](#with-kinesis-example-deployment-pkg-go)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis-create-package.md
c16e90e03184-0
The following example code receives a Kinesis event input and processes the messages that it contains\. For illustration, the code writes some of the incoming event data to CloudWatch Logs\. **Example index\.js** ``` console.log('Loading function'); exports.handler = function(event, context) { //console.log(JSON.stringify(event, null, 2)); event.Records.forEach(function(record) { // Kinesis data is base64 encoded so decode here var payload = Buffer.from(record.kinesis.data, 'base64').toString('ascii'); console.log('Decoded payload:', payload); }); }; ``` Zip up the sample code to create a deployment package\. For instructions, see [AWS Lambda deployment package in Node\.js](nodejs-package.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis-create-package.md
b38a698c6d5b-0
The following is example Java code that receives Kinesis event record data as input and processes it\. For illustration, the code writes some of the incoming event data to CloudWatch Logs\. In the code, `recordHandler` is the handler\. The handler uses the predefined `KinesisEvent` class that is defined in the `aws-lambda-java-events` library\. **Example ProcessKinesisEvents\.java** ``` package example; import com.amazonaws.services.lambda.runtime.Context; import com.amazonaws.services.lambda.runtime.RequestHandler; import com.amazonaws.services.lambda.runtime.events.KinesisEvent; import com.amazonaws.services.lambda.runtime.events.KinesisEvent.KinesisEventRecord; public class ProcessKinesisRecords implements RequestHandler<KinesisEvent, Void>{ @Override public Void handleRequest(KinesisEvent event, Context context) { for(KinesisEventRecord rec : event.getRecords()) { System.out.println(new String(rec.getKinesis().getData().array())); } return null; } } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis-create-package.md
b38a698c6d5b-1
} return null; } } ``` If the handler returns normally without exceptions, Lambda considers the input batch of records as processed successfully and begins reading new records in the stream\. If the handler throws an exception, Lambda considers the input batch of records as not processed and invokes the function with the same batch of records again\. **Dependencies** + `aws-lambda-java-core` + `aws-lambda-java-events` + `aws-java-sdk` Build the code with the Lambda library dependencies to create a deployment package\. For instructions, see [AWS Lambda deployment package in Java](java-package.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis-create-package.md
a837a701e2f7-0
The following is example C\# code that receives Kinesis event record data as input and processes it\. For illustration, the code writes some of the incoming event data to CloudWatch Logs\. In the code, `HandleKinesisRecord` is the handler\. The handler uses the predefined `KinesisEvent` class that is defined in the `Amazon.Lambda.KinesisEvents` library\. **Example ProcessingKinesisEvents\.cs** ``` using System; using System.IO; using System.Text; using Amazon.Lambda.Core; using Amazon.Lambda.KinesisEvents; namespace KinesisStreams { public class KinesisSample { [LambdaSerializer(typeof(JsonSerializer))] public void HandleKinesisRecord(KinesisEvent kinesisEvent) { Console.WriteLine($"Beginning to process {kinesisEvent.Records.Count} records..."); foreach (var record in kinesisEvent.Records) { Console.WriteLine($"Event ID: {record.EventId}"); Console.WriteLine($"Event Name: {record.EventName}"); string recordData = GetRecordContents(record.Kinesis); Console.WriteLine($"Record Data:"); Console.WriteLine(recordData);
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis-create-package.md
a837a701e2f7-1
Console.WriteLine($"Record Data:"); Console.WriteLine(recordData); } Console.WriteLine("Stream processing complete."); } private string GetRecordContents(KinesisEvent.Record streamRecord) { using (var reader = new StreamReader(streamRecord.Data, Encoding.ASCII)) { return reader.ReadToEnd(); } } } } ``` Replace the `Program.cs` in a \.NET Core project with the above sample\. For instructions, see [AWS Lambda Deployment Package in C\#](csharp-package.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis-create-package.md
f4b334ea66f5-0
The following is example Python code that receives Kinesis event record data as input and processes it\. For illustration, the code writes to some of the incoming event data to CloudWatch Logs\. **Example ProcessKinesisRecords\.py** ``` from __future__ import print_function #import json import base64 def lambda_handler(event, context): for record in event['Records']: #Kinesis data is base64 encoded so decode here payload=base64.b64decode(record["kinesis"]["data"]) print("Decoded payload: " + str(payload)) ``` Zip up the sample code to create a deployment package\. For instructions, see [AWS Lambda deployment package in Python](python-package.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis-create-package.md
f313ef3a8ee8-0
The following is example Go code that receives Kinesis event record data as input and processes it\. For illustration, the code writes to some of the incoming event data to CloudWatch Logs\. **Example ProcessKinesisRecords\.go** ``` import ( "strings" "github.com/aws/aws-lambda-go/events" ) func handler(ctx context.Context, kinesisEvent events.KinesisEvent) { for _, record := range kinesisEvent.Records { kinesisRecord := record.Kinesis dataBytes := kinesisRecord.Data dataText := string(dataBytes) fmt.Printf("%s Data = %s \n", record.EventName, dataText) } } ``` Build the executable with `go build` and create a deployment package\. For instructions, see [AWS Lambda deployment package in Go](golang-package.md)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-kinesis-create-package.md
5359535bdda8-0
You can create custom error handling to raise an exception directly from your Lambda function and handle it directly\. The following code samples demonstrate how to do this\. Note that custom errors in Go must import the `errors` module\. ``` package main import ( "errors" "github.com/aws/aws-lambda-go/lambda" ) func OnlyErrors() error { return errors.New("something went wrong!") } func main() { lambda.Start(OnlyErrors) } ``` Which returns the following: ``` { "errorMessage": "something went wrong!", "errorType": "errorString" } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/golang-exceptions.md
09edcb506341-0
Adds permissions to the resource\-based policy of a version of an [AWS Lambda layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html)\. Use this action to grant layer usage permission to other accounts\. You can grant permission to a single account, all AWS accounts, or all accounts in an organization\. To revoke permission, call [RemoveLayerVersionPermission](API_RemoveLayerVersionPermission.md) with the statement ID that you specified when you added it\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddLayerVersionPermission.md
4802e53e7ac6-0
``` POST /2018-10-31/layers/LayerName/versions/VersionNumber/policy?RevisionId=RevisionId HTTP/1.1 Content-type: application/json { "Action": "string", "OrganizationId": "string", "Principal": "string", "StatementId": "string" } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddLayerVersionPermission.md
38219f2d1f17-0
The request uses the following URI parameters\. ** [LayerName](#API_AddLayerVersionPermission_RequestSyntax) ** <a name="SSS-AddLayerVersionPermission-request-LayerName"></a> The name or Amazon Resource Name \(ARN\) of the layer\. Length Constraints: Minimum length of 1\. Maximum length of 140\. Pattern: `(arn:[a-zA-Z0-9-]+:lambda:[a-zA-Z0-9-]+:\d{12}:layer:[a-zA-Z0-9-_]+)|[a-zA-Z0-9-_]+` Required: Yes ** [RevisionId](#API_AddLayerVersionPermission_RequestSyntax) ** <a name="SSS-AddLayerVersionPermission-request-RevisionId"></a> Only update the policy if the revision ID matches the ID specified\. Use this option to avoid modifying a policy that has changed since you last read it\. ** [VersionNumber](#API_AddLayerVersionPermission_RequestSyntax) ** <a name="SSS-AddLayerVersionPermission-request-VersionNumber"></a> The version number\. Required: Yes
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddLayerVersionPermission.md
895281ed5b6d-0
The request accepts the following data in JSON format\. ** [Action](#API_AddLayerVersionPermission_RequestSyntax) ** <a name="SSS-AddLayerVersionPermission-request-Action"></a> The API action that grants access to the layer\. For example, `lambda:GetLayerVersion`\. Type: String Pattern: `lambda:GetLayerVersion` Required: Yes ** [OrganizationId](#API_AddLayerVersionPermission_RequestSyntax) ** <a name="SSS-AddLayerVersionPermission-request-OrganizationId"></a> With the principal set to `*`, grant permission to all accounts in the specified organization\. Type: String Pattern: `o-[a-z0-9]{10,32}` Required: No ** [Principal](#API_AddLayerVersionPermission_RequestSyntax) ** <a name="SSS-AddLayerVersionPermission-request-Principal"></a> An account ID, or `*` to grant permission to all AWS accounts\. Type: String Pattern: `\d{12}|\*|arn:(aws[a-zA-Z-]*):iam::\d{12}:root` Required: Yes
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddLayerVersionPermission.md
895281ed5b6d-1
Required: Yes ** [StatementId](#API_AddLayerVersionPermission_RequestSyntax) ** <a name="SSS-AddLayerVersionPermission-request-StatementId"></a> An identifier that distinguishes the policy from others on the same layer version\. Type: String Length Constraints: Minimum length of 1\. Maximum length of 100\. Pattern: `([a-zA-Z0-9-_]+)` Required: Yes
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddLayerVersionPermission.md
db8b5cf7a66d-0
``` HTTP/1.1 201 Content-type: application/json { "RevisionId": "string", "Statement": "string" } ```
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddLayerVersionPermission.md
7a545f03b5ff-0
If the action is successful, the service sends back an HTTP 201 response\. The following data is returned in JSON format by the service\. ** [RevisionId](#API_AddLayerVersionPermission_ResponseSyntax) ** <a name="SSS-AddLayerVersionPermission-response-RevisionId"></a> A unique identifier for the current revision of the policy\. Type: String ** [Statement](#API_AddLayerVersionPermission_ResponseSyntax) ** <a name="SSS-AddLayerVersionPermission-response-Statement"></a> The permission statement\. Type: String
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddLayerVersionPermission.md
0d9302ec38eb-0
**InvalidParameterValueException** One of the parameters in the request is invalid\. HTTP Status Code: 400 **PolicyLengthExceededException** The permissions policy for the resource is too large\. [Learn more](https://docs.aws.amazon.com/lambda/latest/dg/limits.html) HTTP Status Code: 400 **PreconditionFailedException** The RevisionId provided does not match the latest RevisionId for the Lambda function or alias\. Call the `GetFunction` or the `GetAlias` API to retrieve the latest RevisionId for your resource\. HTTP Status Code: 412 **ResourceConflictException** The resource already exists, or another operation is in progress\. HTTP Status Code: 409 **ResourceNotFoundException** The resource specified in the request does not exist\. HTTP Status Code: 404 **ServiceException** The AWS Lambda service encountered an internal error\. HTTP Status Code: 500 **TooManyRequestsException** The request throughput limit was exceeded\. HTTP Status Code: 429
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddLayerVersionPermission.md
0c63d6559253-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/AddLayerVersionPermission) + [AWS SDK for \.NET](https://docs.aws.amazon.com/goto/DotNetSDKV3/lambda-2015-03-31/AddLayerVersionPermission) + [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/lambda-2015-03-31/AddLayerVersionPermission) + [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/lambda-2015-03-31/AddLayerVersionPermission) + [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/lambda-2015-03-31/AddLayerVersionPermission) + [AWS SDK for JavaScript](https://docs.aws.amazon.com/goto/AWSJavaScriptSDK/lambda-2015-03-31/AddLayerVersionPermission) + [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/lambda-2015-03-31/AddLayerVersionPermission)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddLayerVersionPermission.md
0c63d6559253-1
+ [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/lambda-2015-03-31/AddLayerVersionPermission) + [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/lambda-2015-03-31/AddLayerVersionPermission)
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddLayerVersionPermission.md
fa0c36dea1de-0
Lambda integrates with AWS X\-Ray to enable you to trace, debug, and optimize Lambda applications\. You can use X\-Ray to trace a request as it traverses resources in your application, from the frontend API to storage and database on the backend\. By simply adding the X\-Ray SDK library to your build configuration, you can record errors and latency for any call that your function makes to an AWS service\. The X\-Ray *service map* shows the flow of requests through your application\. The following example from the [error processor](samples-errorprocessor.md) sample application shows an application with two functions\. The primary function processes events and sometimes returns errors\. The second function processes errors that appear in the first's log group and uses the AWS SDK to call X\-Ray, Amazon S3 and Amazon CloudWatch Logs\. [images/sample-errorprocessor-servicemap-l.png](images/sample-errorprocessor-servicemap-l.png) To trace requests that don't have a tracing header, enable active tracing in your function's configuration\. **To enable active tracing** 1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\. 1. Choose a function\. 1. Under **AWS X\-Ray**, choose **Active tracing**\. 1. Choose **Save**\. **Pricing**
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/python-tracing.md
fa0c36dea1de-1
1. Choose **Save**\. **Pricing** X\-Ray has a perpetual free tier\. Beyond the free tier threshold, X\-Ray charges for trace storage and retrieval\. For details, see [AWS X\-Ray pricing](https://aws.amazon.com/xray/pricing/)\. Your function needs permission to upload trace data to X\-Ray\. When you enable active tracing in the Lambda console, Lambda adds the required permissions to your function's [execution role](lambda-intro-execution-role.md)\. Otherwise, add the [AWSXRayDaemonWriteAccess](https://console.aws.amazon.com/iam/home#/policies/arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess) policy to the execution role\. X\-Ray applies a sampling algorithm to ensure that tracing is efficient, while still providing a representative sample of the requests that your application serves\. The default sampling rule is 1 request per second and 5 percent of additional requests\. This sampling rate cannot be configured for Lambda functions\. When active tracing is enabled, Lambda records a trace for a subset of invocations\. Lambda records two *segments*, which creates two nodes on the service map\. The first node represents the Lambda service that receives the invocation request\. The second node is recorded by the function's [runtime](gettingstarted-concepts.md#gettingstarted-concepts-runtimes)\.
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/python-tracing.md