id
stringlengths 14
16
| text
stringlengths 1
2.43k
| source
stringlengths 99
229
|
|---|---|---|
c628232e7b73-1
|
},
{
"Sid": "DevelopEventSourceMappings",
"Effect": "Allow",
"Action": [
"lambda:DeleteEventSourceMapping",
"lambda:UpdateEventSourceMapping",
"lambda:CreateEventSourceMapping"
],
"Resource": "*",
"Condition": {
"StringLike": {
"lambda:FunctionArn": "arn:aws:lambda:*:*:function:intern-*"
}
}
},
{
"Sid": "PassExecutionRole",
"Effect": "Allow",
"Action": [
"iam:ListRolePolicies",
"iam:ListAttachedRolePolicies",
"iam:GetRole",
"iam:GetRolePolicy",
"iam:PassRole",
"iam:SimulatePrincipalPolicy"
],
"Resource": "arn:aws:iam::*:role/intern-lambda-execution-role"
},
{
"Sid": "ViewExecutionRolePolicies",
"Effect": "Allow",
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-identity-based.md
|
c628232e7b73-2
|
},
{
"Sid": "ViewExecutionRolePolicies",
"Effect": "Allow",
"Action": [
"iam:GetPolicy",
"iam:GetPolicyVersion"
],
"Resource": "arn:aws:iam::aws:policy/*"
},
{
"Sid": "ViewLogs",
"Effect": "Allow",
"Action": [
"logs:*"
],
"Resource": "arn:aws:logs:*:*:log-group:/aws/lambda/intern-*"
}
]
}
```
The permissions in the policy are organized into statements based on the [resources and conditions](lambda-api-permissions-ref.md) that they support\.
+ `ReadOnlyPermissions` β The Lambda console uses these permissions when you browse and view functions\. They don't support resource patterns or conditions\.
```
"Action": [
"lambda:GetAccountSettings",
"lambda:ListFunctions",
"lambda:ListTags",
"lambda:GetEventSourceMapping",
"lambda:ListEventSourceMappings",
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-identity-based.md
|
c628232e7b73-3
|
"lambda:GetEventSourceMapping",
"lambda:ListEventSourceMappings",
"iam:ListRoles"
],
"Resource": "*"
```
+ `DevelopFunctions` β Use any Lambda action that operates on functions prefixed with `intern-`, *except* `AddPermission` and `PutFunctionConcurrency`\. `AddPermission` modifies the [resource\-based policy](access-control-resource-based.md) on the function and can have security implications\. `PutFunctionConcurrency` reserves scaling capacity for a function and can take capacity away from other functions\.
```
"NotAction": [
"lambda:AddPermission",
"lambda:PutFunctionConcurrency"
],
"Resource": "arn:aws:lambda:*:*:function:intern-*"
```
+ `DevelopEventSourceMappings` β Manage event source mappings on functions that are prefixed with `intern-`\. These actions operate on event source mappings, but you can restrict them by function with a *condition*\.
```
"Action": [
"lambda:DeleteEventSourceMapping",
"lambda:UpdateEventSourceMapping",
"lambda:CreateEventSourceMapping"
],
"Resource": "*",
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-identity-based.md
|
c628232e7b73-4
|
"lambda:CreateEventSourceMapping"
],
"Resource": "*",
"Condition": {
"StringLike": {
"lambda:FunctionArn": "arn:aws:lambda:*:*:function:intern-*"
}
}
```
+ `PassExecutionRole` β View and pass only a role named `intern-lambda-execution-role`, which must be created and managed by a user with IAM permissions\. `PassRole` is used when you assign an execution role to a function\.
```
"Action": [
"iam:ListRolePolicies",
"iam:ListAttachedRolePolicies",
"iam:GetRole",
"iam:GetRolePolicy",
"iam:PassRole",
"iam:SimulatePrincipalPolicy"
],
"Resource": "arn:aws:iam::*:role/intern-lambda-execution-role"
```
+ `ViewExecutionRolePolicies` β View the AWS\-provided managed policies that are attached to the execution role\. This lets you view the function's permissions in the console, but doesn't include permission to view policies that were created by other users in the account\.
```
"Action": [
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-identity-based.md
|
c628232e7b73-5
|
```
"Action": [
"iam:GetPolicy",
"iam:GetPolicyVersion"
],
"Resource": "arn:aws:iam::aws:policy/*"
```
+ `ViewLogs` β Use CloudWatch Logs to view logs for functions that are prefixed with `intern-`\.
```
"Action": [
"logs:*"
],
"Resource": "arn:aws:logs:*:*:log-group:/aws/lambda/intern-*"
```
This policy allows a user to get started with Lambda, without putting other users' resources at risk\. It doesn't allow a user to configure a function to be triggered by or call other AWS services, which requires broader IAM permissions\. It also doesn't include permission to services that don't support limited\-scope policies, like CloudWatch and X\-Ray\. Use the read\-only policies for these services to give the user access to metrics and trace data\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-identity-based.md
|
c628232e7b73-6
|
When you configure triggers for your function, you need access to use the AWS service that invokes your function\. For example, to configure an Amazon S3 trigger, you need permission to use the Amazon S3 actions that manage bucket notifications\. Many of these permissions are included in the **AWSLambdaFullAccess** managed policy\. Example policies 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/access-control-identity-based.md
|
628e6ada64f9-0
|
The following policy grants a user permission to create layers and use them with functions\. The resource patterns allow the user to work in any AWS Region and with any layer version, as long as the name of the layer starts with `test-`\.
**Example layer development policy**
```
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublishLayers",
"Effect": "Allow",
"Action": [
"lambda:PublishLayerVersion"
],
"Resource": "arn:aws:lambda:*:*:layer:test-*"
},
{
"Sid": "ManageLayerVersions",
"Effect": "Allow",
"Action": [
"lambda:GetLayerVersion",
"lambda:DeleteLayerVersion"
],
"Resource": "arn:aws:lambda:*:*:layer:test-*:*"
}
]
}
```
You can also enforce layer use during function creation and configuration with the `lambda:Layer` condition\. For example, you can prevent users from using layers published by other accounts\. The following policy adds a condition to the `CreateFunction` and `UpdateFunctionConfiguration` actions to require that any layers specified come from account `123456789012`\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-identity-based.md
|
628e6ada64f9-1
|
```
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ConfigureFunctions",
"Effect": "Allow",
"Action": [
"lambda:CreateFunction",
"lambda:UpdateFunctionConfiguration"
],
"Resource": "*",
"Condition": {
"ForAllValues:StringLike": {
"lambda:Layer": [
"arn:aws:lambda:*:123456789012:layer:*:*"
]
}
}
}
]
}
```
To ensure that the condition applies, verify that no other statements grant the user permission to these actions\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-identity-based.md
|
91aded5740ad-0
|
You can apply any of the preceding policies and statements to a role, which you can then share with another account to give it access to your Lambda resources\. Unlike an IAM user, a role doesn't have credentials for authentication\. Instead, it has a *trust policy* that specifies who can assume the role and use its permissions\.
You can use cross\-account roles to give accounts that you trust access to Lambda actions and resources\. If you just want to grant permission to invoke a function or use a layer, use [resource\-based policies](access-control-resource-based.md) instead\.
For more information, see [IAM roles](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html) in the *IAM User Guide*\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-identity-based.md
|
9ca2ff57a730-0
|
You can use condition keys for VPC settings to provide additional permission controls for your Lambda functions\. For example, you can enforce that all Lambda functions in your organization are connected to a VPC\. You can also specify the subnets and security groups that the functions are allowed to use, or are denied from using\.
For more information, see [Using IAM condition keys for VPC settings](configuration-vpc.md#vpc-conditions)\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/access-control-identity-based.md
|
27d89af512ee-0
|
Sample code is available for the following languages\.
**Topics**
+ [Node\.js](#with-sqs-example-deployment-pkg-nodejs)
+ [Java](#with-sqs-example-deployment-pkg-java)
+ [C\#](#with-sqs-example-deployment-pkg-dotnet)
+ [Go](#with-sqs-example-deployment-pkg-go)
+ [Python](#with-sqs-example-deployment-pkg-python)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-sqs-create-package.md
|
8db6a844076e-0
|
The following is example code that receives an Amazon SQS event message as input and processes it\. For illustration, the code writes some of the incoming event data to CloudWatch Logs\.
**Example index\.js \(Node\.js 8\)**
```
exports.handler = async function(event, context) {
event.Records.forEach(record => {
const { body } = record;
console.log(body);
});
return {};
}
```
**Example index\.js \(Node\.js 6\)**
```
event.Records.forEach(function(record) {
var body = record.body;
console.log(body);
});
callback(null, "message");
};
```
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-sqs-create-package.md
|
30be4874cc1e-0
|
The following is example Java code that receives an Amazon SQS event message as input and processes it\. For illustration, the code writes some of the incoming event data to CloudWatch Logs\.
In the code, `handleRequest` is the handler\. The handler uses the predefined `SQSEvent` class that is defined in the `aws-lambda-java-events` library\.
**Example Handler\.java**
```
package example;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
import com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
public class Handler implements RequestHandler<SQSEvent, Void>{
@Override
public Void handleRequest(SQSEvent event, Context context)
{
for(SQSMessage msg : event.getRecords()){
System.out.println(new String(msg.getBody()));
}
return null;
}
}
```
**Dependencies**
+ `aws-lambda-java-core`
+ `aws-lambda-java-events`
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-sqs-create-package.md
|
30be4874cc1e-1
|
**Dependencies**
+ `aws-lambda-java-core`
+ `aws-lambda-java-events`
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-sqs-create-package.md
|
b9e8d5197a64-0
|
The following is example C\# code that receives an Amazon SQS event message as input and processes it\. For illustration, the code writes some of the incoming event data to the console\.
In the code, `handleRequest` is the handler\. The handler uses the predefined `SQSEvent` class that is defined in the `AWS.Lambda.SQSEvents` library\.
**Example ProcessingSQSRecords\.cs**
```
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace SQSLambdaFunction
{
public class SQSLambdaFunction
{
public string HandleSQSEvent(SQSEvent sqsEvent, ILambdaContext context)
{
Console.WriteLine($"Beginning to process {sqsEvent.Records.Count} records...");
foreach (var record in sqsEvent.Records)
{
Console.WriteLine($"Message ID: {record.MessageId}");
Console.WriteLine($"Event Source: {record.EventSource}");
Console.WriteLine($"Record Body:");
Console.WriteLine(record.Body);
}
Console.WriteLine("Processing complete.");
return $"Processed {sqsEvent.Records.Count} records.";
}
}
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-sqs-create-package.md
|
b9e8d5197a64-1
|
return $"Processed {sqsEvent.Records.Count} records.";
}
}
}
```
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-sqs-create-package.md
|
446af432bc02-0
|
The following is example Go code that receives an Amazon SQS event message as input and processes it\. For illustration, the code writes some of the incoming event data to CloudWatch Logs\.
In the code, `handler` is the handler\. The handler uses the predefined `SQSEvent` class that is defined in the `aws-lambda-go-events` library\.
**Example ProcessSQSRecords\.go**
```
package main
import (
"context"
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func handler(ctx context.Context, sqsEvent events.SQSEvent) error {
for _, message := range sqsEvent.Records {
fmt.Printf("The message %s for event source %s = %s \n", message.MessageId, message.EventSource, message.Body)
}
return nil
}
func main() {
lambda.Start(handler)
}
```
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-sqs-create-package.md
|
3a0da8c7ee48-0
|
The following is example Python code that accepts an Amazon SQS record as input and processes it\. For illustration, the code writes to some of the incoming event data to CloudWatch Logs\.
Follow the instructions to create a AWS Lambda function deployment package\.
**Example ProcessSQSRecords\.py**
```
from __future__ import print_function
def lambda_handler(event, context):
for record in event['Records']:
print ("test")
payload=record["body"]
print(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-sqs-create-package.md
|
c999d9622c26-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](services-cloudwatchevents-tutorial.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
Parameters:
NotificationEmail:
Type: String
Resources:
CheckWebsitePeriodically:
Type: [AWS::Serverless::Function](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html)
Properties:
Handler: LambdaFunctionOverHttps.handler
Runtime: runtime
Policies: AmazonDynamoDBFullAccess
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/with-scheduledevents-example-use-app-spec.md
|
c999d9622c26-1
|
Handler: LambdaFunctionOverHttps.handler
Runtime: runtime
Policies: AmazonDynamoDBFullAccess
Events:
CheckWebsiteScheduledEvent:
Type: Schedule
Properties:
Schedule: rate(1 minute)
AlarmTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Protocol: email
Endpoint: !Ref NotificationEmail
Alarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmActions:
- !Ref AlarmTopic
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: FunctionName
Value: !Ref CheckWebsitePeriodically
EvaluationPeriods: 1
MetricName: Errors
Namespace: AWS/Lambda
Period: 60
Statistic: Sum
Threshold: '1'
```
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-scheduledevents-example-use-app-spec.md
|
b8161cd2b714-0
|
Details about an [AWS Lambda layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html)\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_LayersListItem.md
|
12a99881623d-0
|
**LatestMatchingVersion** <a name="SSS-Type-LayersListItem-LatestMatchingVersion"></a>
The newest version of the layer\.
Type: [LayerVersionsListItem](API_LayerVersionsListItem.md) object
Required: No
**LayerArn** <a name="SSS-Type-LayersListItem-LayerArn"></a>
The Amazon Resource Name \(ARN\) of the function layer\.
Type: String
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-_]+`
Required: No
**LayerName** <a name="SSS-Type-LayersListItem-LayerName"></a>
The name of the layer\.
Type: String
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: No
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_LayersListItem.md
|
af361192953d-0
|
For more information about using this API in one of the language\-specific AWS SDKs, see the following:
+ [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/lambda-2015-03-31/LayersListItem)
+ [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/lambda-2015-03-31/LayersListItem)
+ [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/lambda-2015-03-31/LayersListItem)
+ [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/lambda-2015-03-31/LayersListItem)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_LayersListItem.md
|
38ce005c7f7c-0
|
AWS Step Functions is an orchestration service that lets you connect Lambda functions together into serverless workflows, called state machines\. Use Step Functions to orchestrate serverless applications workflows \(for example, a store checkout process\), build long\-running workflows for IT automation and human\-approval use cases, or create high\-volume short\-duration workflows for streaming data processing and ingestion\.
**Topics**
+ [State machine application patterns](stepfunctions-patterns.md)
+ [Managing state machines in the Lambda console](stepfunctions-lc.md)
+ [Orchestration examples with Step Functions](services-stepfunctions.md)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/lambda-stepfunctions.md
|
d3dff33aaf95-0
|
When your code raises an error, Lambda generates a JSON representation of the error\. This error document appears in the invocation log and, for synchronous invocations, in the output\.
**Example index\.js file β Reference error**
```
exports.handler = async function() {
return x + 10
}
```
This code results in a reference error\. Lambda catches the error and generates a JSON document with fields for the error message, the type, and the stack trace\.
```
{
"errorType": "ReferenceError",
"errorMessage": "x is not defined",
"trace": [
"ReferenceError: x is not defined",
" at Runtime.exports.handler (/var/task/index.js:2:3)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:63:25)",
" at process._tickCallback (internal/process/next_tick.js:68:7)"
]
}
```
When you invoke the function from the command line, the AWS CLI splits the response into two documents\. To indicate that a function error occurred, the response displayed in the terminal includes a `FunctionError` field\. The response or error returned by the function is written to the output file\.
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/nodejs-exceptions.md
|
d3dff33aaf95-1
|
```
$ aws lambda invoke --function-name my-function out.json
{
"StatusCode": 200,
"FunctionError": "Unhandled",
"ExecutedVersion": "$LATEST"
}
```
View the output file to see the error document\.
```
$ cat out.json
{"errorType":"ReferenceError","errorMessage":"x is not defined","trace":["ReferenceError: x is not defined"," at Runtime.exports.handler (/var/task/index.js:2:3)"," at Runtime.handleOnce (/var/runtime/Runtime.js:63:25)"," at process._tickCallback (internal/process/next_tick.js:68:7)"]}
```
**Note**
The 200 \(success\) status code in the response from Lambda indicates that there wasn't an error with the request that you sent to Lambda\. For issues that result in an error status code, see [Errors](API_Invoke.md#API_Invoke_Errors)\.
Lambda also records up to 256 KB of the error object in the function's logs\. To view logs when you invoke the function from the command line, use the `--log-type` option and decode the base64 string in the response\.
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/nodejs-exceptions.md
|
d3dff33aaf95-2
|
```
$ aws lambda invoke --function-name my-function out.json --log-type Tail \
--query 'LogResult' --output text | base64 -d
START RequestId: 8bbbfb91-a3ff-4502-b1b7-cb8f6658de64 Version: $LATEST
2019-06-05T22:11:27.082Z 8bbbfb91-a3ff-4502-b1b7-cb8f6658de64 ERROR Invoke Error {"errorType":"ReferenceError","errorMessage":"x is not defined","stack":["ReferenceError: x is not defined"," at Runtime.exports.handler (/var/task/index.js:2:3)"," at Runtime.handleOnce (/var/runtime/Runtime.js:63:25)"," at process._tickCallback (internal/process/next_tick.js:68:7)"]}
END RequestId: 8bbbfb91-a3ff-4502-b1b7-cb8f6658de64
REPORT RequestId: 8bbbfb91-a3ff-4502-b1b7-cb8f6658de64 Duration: 76.85 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 74 MB
```
For more information about logs, see [AWS Lambda function logging in Node\.js](nodejs-logging.md)\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/nodejs-exceptions.md
|
d3dff33aaf95-3
|
```
For more information about logs, see [AWS Lambda function logging in Node\.js](nodejs-logging.md)\.
Depending on the event source, AWS Lambda might retry the failed Lambda function\. For example, if Kinesis is the event source, AWS Lambda retries the failed invocation until the Lambda function succeeds or the records in the stream expire\. For more information on retries, see [Error handling and automatic retries in AWS Lambda](invocation-retries.md)\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/nodejs-exceptions.md
|
f0b5a7d035c0-0
|
The list manager sample application demonstrates the use of AWS Lambda to process records in an Amazon Kinesis data stream\. A Lambda event source mapping reads records from the stream in batches and invokes a Lambda function\. The function uses information from the records to update documents in Amazon DynamoDB and stores the records it processes in Amazon Relational Database Service \(Amazon RDS\)\.
![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/sample-listmanager.png)
Clients send records to a Kinesis stream, which stores them and makes them available for processing\. The Kinesis stream is used like a queue to buffer records until they can be processed\. Unlike an Amazon SQS queue, records in a Kinesis stream are not deleted after they are processed, so multiple consumers can process the same data\. Records in Kinesis are also processed in order, where queue items can be delivered out of order\. Records are deleted from the stream after 7 days\.
In addition to the function that processes events, the application includes a second function for performing administrative tasks on the database\. Function code is available in the following files:
+ Processor β [processor/index\.js](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/list-manager/processor/index.js)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-listmanager.md
|
f0b5a7d035c0-1
|
+ Database admin β [dbadmin/index\.js](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/list-manager/dbadmin/index.js)
You can deploy the sample in a few minutes with the AWS CLI and AWS CloudFormation\. To download, configure, and deploy it in your account, follow the instructions in the [README](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/list-manager)\.
**Topics**
+ [Architecture and event structure](#samples-listmanager-architecture)
+ [Instrumentation with AWS X\-Ray](#samples-listmanager-instrumentation)
+ [AWS CloudFormation templates and additional resources](#samples-listmanager-template)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-listmanager.md
|
b04de54d0f19-0
|
The sample application uses the following AWS services:
+ Kinesis β Receives events from clients and stores them temporarily for processing\.
+ AWS Lambda β Reads from the Kinesis stream and sends events to the function's handler code\.
+ DynamoDB β Stores lists generated by the application\.
+ Amazon RDS β Stores a copy of processed records in a relational database\.
+ AWS Secrets Manager β Stores the database password\.
+ Amazon VPC β Provides a private local network for communication between the function and database\.
**Pricing**
Standard charges apply for each service\.
The application processes JSON documents from clients that contain information necessary to update a list\. It supports two types of list: tally and ranking\. A *tally* contains values that are added to the current value for key if it exists\. Each entry processed for a user increases the value of a key in the specified table\.
The following example shows a document that increases the `xp` \(experience points\) value for a user's `stats` list\.
**Example record β Tally type**
```
{
"title": "stats",
"user": "bill",
"type": "tally",
"entries": {
"xp": 83
}
}
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-listmanager.md
|
b04de54d0f19-1
|
"entries": {
"xp": 83
}
}
```
A *ranking* contains a list of entries where the value is the order in which they are ranked\. A ranking can be updated with different values that overwrite the current value, instead of incrementing it\. The following example shows a ranking of favorite movies:
**Example record β Ranking type**
```
{
"title": "favorite movies",
"user": "mike",
"type": "rank",
"entries": {
"blade runner": 1,
"the empire strikes back": 2,
"alien": 3
}
}
```
A Lambda [event source mapping](invocation-eventsourcemapping.md) read records from the stream in batches and invokes the processor function\. The event that the function handler received contains an array of objects that each contain details about a record, such as when it was received, details about the stream, and an encoded representation of the original record document\.
**Example [events/kinesis\.json](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/list-manager/events/kinesis.json) β Record**
```
{
"Records": [
{
"kinesis": {
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-listmanager.md
|
b04de54d0f19-2
|
```
{
"Records": [
{
"kinesis": {
"kinesisSchemaVersion": "1.0",
"partitionKey": "0",
"sequenceNumber": "49598630142999655949899443842509554952738656579378741250",
"data": "eyJ0aXRsZSI6ICJmYXZvcml0ZSBtb3ZpZXMiLCAidXNlciI6ICJyZGx5c2N0IiwgInR5cGUiOiAicmFuayIsICJlbnRyaWVzIjogeyJibGFkZSBydW5uZXIiOiAyLCAidGhlIGVtcGlyZSBzdHJpa2VzIGJhY2siOiAzLCAiYWxpZW4iOiAxfX0=",
"approximateArrivalTimestamp": 1570667770.615
},
"eventSource": "aws:kinesis",
"eventVersion": "1.0",
"eventID": "shardId-000000000000:49598630142999655949899443842509554952738656579378741250",
"eventName": "aws:kinesis:record",
"invokeIdentityArn": "arn:aws:iam::123456789012:role/list-manager-processorRole-7FYXMPLH7IUS",
"awsRegion": "us-east-2",
"eventSourceARN": "arn:aws:kinesis:us-east-2:123456789012:stream/list-manager-stream-87B3XMPLF1AZ"
},
...
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-listmanager.md
|
b04de54d0f19-3
|
},
...
```
When it's decoded, the data contains a record\. The function uses the record to update the user's list and an aggregate list that stores accumulated values across all users\. It also stores a copy of the event in the application's database\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-listmanager.md
|
820b962d6dfc-0
|
The application uses [AWS X\-Ray](services-xray.md) to trace function invocations and the calls that functions make to AWS services\. X\-Ray uses the trace data that it receives from functions to create a service map that helps you identify errors\. The following service map shows the function communicating with two DynamoDB tables and a MySQL database\.
![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/listmanager-servicemap.png)
The Node\.js function is configured for active tracing in the template, and is instrumented with the AWS X\-Ray SDK for Node\.js in code\. The X\-Ray SDK records a subsegment for each call made with an AWS SDK or MySQL client\.
![\[Image NOT FOUND\]](http://docs.aws.amazon.com/lambda/latest/dg/images/listmanager-trace.png)
The function uses the AWS SDK for JavaScript in Node\.js to read and write to two tables for each record\. The primary table stores the current state of each combination of list name and user\. The aggregate table stores lists that combine data from multiple users\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-listmanager.md
|
9edc9bb74023-0
|
The application is implemented in Node\.js modules and deployed with an AWS CloudFormation template and shell scripts\. The application template creates two functions, a Kinesis stream, DynamoDB tables and the following supporting resources\.
**Application resources**
+ Execution role β An IAM role that grants the functions permission to access other AWS services\.
+ Lambda event source mapping β Reads records from the data stream and invokes the function\.
View the [application template](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/list-manager/template.yml) on GitHub\.
A second template, [template\-vpcrds\.yml](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/list-manager/template.yml), creates the Amazon VPC and database resources\. While it is possible to create all of the resources in one template, separating them makes it easier to clean up the application and allows the database to be reused with multiple applications\.
**Infrastructure resources**
+ VPC β A virtual private cloud network with private subnets, a route table, and a VPC endpoint that allows the function to communicate with DynamoDB without an internet connection\.
+ Database β An Amazon RDS database instance and a subnet group that connects it to the VPC\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/samples-listmanager.md
|
936bc0cb1e2a-0
|
Details about a version of an [AWS Lambda layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html)\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_LayerVersionContentOutput.md
|
307d0ea70ee4-0
|
**CodeSha256** <a name="SSS-Type-LayerVersionContentOutput-CodeSha256"></a>
The SHA\-256 hash of the layer archive\.
Type: String
Required: No
**CodeSize** <a name="SSS-Type-LayerVersionContentOutput-CodeSize"></a>
The size of the layer archive in bytes\.
Type: Long
Required: No
**Location** <a name="SSS-Type-LayerVersionContentOutput-Location"></a>
A link to the layer archive in Amazon S3 that is valid for 10 minutes\.
Type: String
Required: No
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_LayerVersionContentOutput.md
|
8d0548edb637-0
|
For more information about using this API in one of the language\-specific AWS SDKs, see the following:
+ [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/lambda-2015-03-31/LayerVersionContentOutput)
+ [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/lambda-2015-03-31/LayerVersionContentOutput)
+ [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/lambda-2015-03-31/LayerVersionContentOutput)
+ [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/lambda-2015-03-31/LayerVersionContentOutput)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_LayerVersionContentOutput.md
|
fdba7fe56b3d-0
|
AWS Lambda conforms to the AWS [shared responsibility model](http://aws.amazon.com/compliance/shared-responsibility-model/), which includes regulations and guidelines for data protection\. AWS is responsible for protecting the global infrastructure that runs all the AWS services\. AWS maintains control over data hosted on this infrastructure, including the security configuration controls for handling customer content and personal data\. AWS customers and APN partners, acting either as data controllers or data processors, are responsible for any personal data that they put in the AWS Cloud\.
For data protection purposes, we recommend that you protect AWS account credentials and set up individual user accounts with AWS Identity and Access Management \(IAM\), so that each user is given only the permissions necessary to fulfill their job duties\. We also recommend that you secure your data in the following ways:
+ Use multi\-factor authentication \(MFA\) with each account\.
+ Use SSL/TLS to communicate with AWS resources\.
+ Set up API and user activity logging with AWS CloudTrail\.
+ Use AWS encryption solutions, along with all default security controls within AWS services\.
+ Use advanced managed security services such as Amazon Macie, which assists in discovering and securing personal data that is stored in Amazon S3\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security-dataprotection.md
|
fdba7fe56b3d-1
|
+ Use advanced managed security services such as Amazon Macie, which assists in discovering and securing personal data that is stored in Amazon S3\.
We strongly recommend that you never put sensitive identifying information, such as your customers' account numbers, into free\-form fields or metadata such as function names and tags\. This includes when you work with Lambda or other AWS services using the console, API, AWS CLI, or AWS SDKs\. Any data that you enter into metadata might get picked up for inclusion in diagnostic logs\. When you provide a URL to an external server, don't include credentials information in the URL to validate your request to that server\.
For more information about data protection, see the [AWS shared responsibility model and GDPR](http://aws.amazon.com/blogs/security/the-aws-shared-responsibility-model-and-gdpr/) blog post on the *AWS Security Blog*\.
**Topics**
+ [Encryption in transit](#security-privacy-intransit)
+ [Encryption at rest](#security-privacy-atrest)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security-dataprotection.md
|
8edf7aa2686b-0
|
Lambda API endpoints only support secure connections over HTTPS\. When you manage Lambda resources with the AWS Management Console, AWS SDK, or the Lambda API, all communication is encrypted with Transport Layer Security \(TLS\)\.
When you [connect your function to a file system](configuration-filesystem.md), Lambda uses [Encryption in transit](https://docs.aws.amazon.com/efs/latest/ug/encryption.html) for all connections\.
For a full list of API endpoints, see [AWS Regions and endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html) in the AWS General Reference\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security-dataprotection.md
|
e0e6fc643fec-0
|
You can use environment variables to store secrets securely for use with Lambda functions\. Lambda always encrypts environment variables at rest\.
Additionally, you can use the following features to customize how environment variables are encrypted\.
+ **Key configuration** β On a per\-function basis, you can configure Lambda to use an encryption key that you create and manage in AWS Key Management Service\. These are referred to as *customer managed* customer master keys \(CMKs\) or customer managed keys\. If you don't configure a customer managed key, Lambda uses an AWS managed CMK named `aws/lambda`, which Lambda creates in your account\.
+ **Encryption helpers** β The Lambda console lets you encrypt environment variable values client side, before sending them to Lambda\. This enhances security further by preventing secrets from being displayed unencrypted in the Lambda console, or in function configuration that's returned by the Lambda API\. The console also provides sample code that you can adapt to decrypt the values in your function handler\.
For more information, see [Using AWS Lambda environment variables](configuration-envvars.md)\.
Lambda always encrypts files that you upload to Lambda, including [deployment packages](gettingstarted-features.md#gettingstarted-features-package) and [layer archives](configuration-layers.md)\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security-dataprotection.md
|
e0e6fc643fec-1
|
Amazon CloudWatch Logs and AWS X\-Ray also encrypt data by default, and can be configured to use a customer managed key\. For details, see [Encrypt log data in CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html) and [Data protection in AWS X\-Ray](https://docs.aws.amazon.com/xray/latest/devguide/xray-console-encryption.html)\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/security-dataprotection.md
|
87ae17d8f3e4-0
|
A deployment package is a ZIP archive that contains your function code and dependencies\. You need to create a deployment package if you use the Lambda API to manage functions, or if you need to include libraries and dependencies other than the AWS SDK\. You can upload the package directly to Lambda, or you can use an Amazon S3 bucket, and then upload it to Lambda\. If the deployment package is larger than 50 MB, you must use Amazon S3\.
If you use the Lambda [console editor](code-editor.md) to author your function, the console manages the deployment package\. You can use this method as long as you don't need to add any libraries\. You can also use it to update a function that already has libraries in the deployment package, as long as the total size doesn't exceed 3 MB\.
**Note**
To keep your deployment package size small, package your function's dependencies in layers\. Layers let you manage your dependencies independently, can be used by multiple functions, and can be shared with other accounts\. For details, see [AWS Lambda layers](configuration-layers.md)\.
**Topics**
+ [Updating a function with no dependencies](#nodejs-package-codeonly)
+ [Updating a function with additional dependencies](#nodejs-package-dependencies)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/nodejs-package.md
|
ffd850793142-0
|
To update a function by using the Lambda API, use the [UpdateFunctionCode](API_UpdateFunctionCode.md) operation\. Create an archive that contains your function code, and upload it using the AWS CLI\.
**To update a Node\.js function with no dependencies**
1. Create a ZIP archive\.
```
~/my-function$ zip function.zip index.js
```
1. Use the `update-function-code` command to upload the package\.
```
~/my-function$ aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip
{
"FunctionName": "my-function",
"FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function",
"Runtime": "nodejs12.x",
"Role": "arn:aws:iam::123456789012:role/lambda-role",
"Handler": "index.handler",
"CodeSha256": "Qf0hMc1I2di6YFMi9aXm3JtGTmcDbjniEuiYonYptAk=",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "Active"
},
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/nodejs-package.md
|
ffd850793142-1
|
"Version": "$LATEST",
"TracingConfig": {
"Mode": "Active"
},
"RevisionId": "983ed1e3-ca8e-434b-8dc1-7d72ebadd83d",
...
}
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/nodejs-package.md
|
cbdd0ded384e-0
|
If your function depends on libraries other than the SDK for JavaScript, use [npm](https://www.npmjs.com/) to include them in your deployment package\. Ensure that the Node\.js version in your local environment matches the Node\.js version of your function\. If any of the libraries use native code, use an [Amazon Linux environment ](https://aws.amazon.com/blogs/compute/nodejs-packages-in-lambda/) to create the deployment package\.
You can add the SDK for JavaScript to the deployment package if you need a newer version than the one [included on the runtime](lambda-nodejs.md), or to ensure that the version doesn't change in the future\.
**To update a Node\.js function with dependencies**
1. Open a command line terminal or shell\. Ensure that the Node\.js version in your local environment matches the Node\.js version of your function\.
1. Install libraries in the node\_modules directory with the `npm install` command\.
```
~/my-function$ npm install aws-xray-sdk
```
This creates a folder structure that's similar to the following\.
```
~/my-function
βββ index.js
βββ node_modules
βββ async
βββ async-listener
βββ atomic-batcher
βββ aws-sdk
βββ aws-xray-sdk
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/nodejs-package.md
|
cbdd0ded384e-1
|
βββ async-listener
βββ atomic-batcher
βββ aws-sdk
βββ aws-xray-sdk
βββ aws-xray-sdk-core
```
1. Create a ZIP file that contains the contents of your project folder\.
```
~/my-function$ zip -r function.zip .
```
1. Use the `update-function-code` command to upload the package\.
```
~/my-function$ aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip
{
"FunctionName": "my-function",
"FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function",
"Runtime": "nodejs12.x",
"Role": "arn:aws:iam::123456789012:role/lambda-role",
"Handler": "index.handler",
"CodeSha256": "Qf0hMc1I2di6YFMi9aXm3JtGTmcDbjniEuiYonYptAk=",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "Active"
},
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/nodejs-package.md
|
cbdd0ded384e-2
|
"Version": "$LATEST",
"TracingConfig": {
"Mode": "Active"
},
"RevisionId": "983ed1e3-ca8e-434b-8dc1-7d72ebadd83d",
...
}
```
In addition to code and libraries, your deployment package can also contain executable files and other resources\. For more information, see the following:
+ [Running executables in AWS Lambda](https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/)
+ [Using packages and native nodejs modules in AWS Lambda ](https://aws.amazon.com/blogs/compute/nodejs-packages-in-lambda/)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/nodejs-package.md
|
d7ce4dcebefd-0
|
In an AWS CloudFormation template, you can specify a Lambda function as the target of a custom resource\. Use custom resources to process parameters, retrieve configuration values, or call other AWS services during stack lifecycle events\.
The following example invokes a function that's defined elsewhere in the template\.
**Example β Custom resource definition**
```
Resources:
primerinvoke:
Type: [AWS::CloudFormation::CustomResource](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html)
Version: "1.0"
Properties:
ServiceToken: !GetAtt primer.Arn
FunctionName: !Ref randomerror
```
The service token is the Amazon Resource Name \(ARN\) of the function that AWS CloudFormation invokes when you create, update, or delete the stack\. You can also include additional properties like `FunctionName`, which AWS CloudFormation passes to your function as is\.
AWS CloudFormation invokes your Lambda function [asynchronously](invocation-async.md) with an event that includes a callback URL\.
**Example β AWS CloudFormation message event**
```
{
"RequestType": "Create",
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudformation.md
|
d7ce4dcebefd-1
|
**Example β AWS CloudFormation message event**
```
{
"RequestType": "Create",
"ServiceToken": "arn:aws:lambda:us-east-2:123456789012:function:lambda-error-processor-primer-14ROR2T3JKU66",
"ResponseURL": "https://cloudformation-custom-resource-response-useast2.s3-us-east-2.amazonaws.com/arn%3Aaws%3Acloudformation%3Aus-east-2%3A123456789012%3Astack/lambda-error-processor/1134083a-2608-1e91-9897-022501a2c456%7Cprimerinvoke%7C5d478078-13e9-baf0-464a-7ef285ecc786?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=1555451971&Signature=28UijZePE5I4dvukKQqM%2F9Rf1o4%3D",
"StackId": "arn:aws:cloudformation:us-east-2:123456789012:stack/lambda-error-processor/1134083a-2608-1e91-9897-022501a2c456",
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudformation.md
|
d7ce4dcebefd-2
|
"RequestId": "5d478078-13e9-baf0-464a-7ef285ecc786",
"LogicalResourceId": "primerinvoke",
"ResourceType": "AWS::CloudFormation::CustomResource",
"ResourceProperties": {
"ServiceToken": "arn:aws:lambda:us-east-2:123456789012:function:lambda-error-processor-primer-14ROR2T3JKU66",
"FunctionName": "lambda-error-processor-randomerror-ZWUC391MQAJK"
}
}
```
The function is responsible for returning a response to the callback URL that indicates success or failure\. For the full response syntax, see [Custom resource response objects](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-responses.html)\.
**Example β AWS CloudFormation custom resource response**
```
{
"Status": "SUCCESS",
"PhysicalResourceId": "2019/04/18/[$LATEST]b3d1bfc65f19ec610654e4d9b9de47a0",
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudformation.md
|
d7ce4dcebefd-3
|
"StackId": "arn:aws:cloudformation:us-east-2:123456789012:stack/lambda-error-processor/1134083a-2608-1e91-9897-022501a2c456",
"RequestId": "5d478078-13e9-baf0-464a-7ef285ecc786",
"LogicalResourceId": "primerinvoke"
}
```
AWS CloudFormation provides a library called `cfn-response` that handles sending the response\. If you define your function within a template, you can require the library by name\. AWS CloudFormation then adds the library to the deployment package that it creates for the function\.
The following example function invokes a second function\. If the call succeeds, the function sends a success response to AWS CloudFormation, and the stack update continues\. The template uses the [AWS::Serverless::Function](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html) resource type provided by AWS Serverless Application Model\.
**Example [error\-processor/template\.yml](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/error-processor/template.yml) β Custom resource function**
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudformation.md
|
d7ce4dcebefd-4
|
```
Transform: 'AWS::Serverless-2016-10-31'
Resources:
primer:
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
InlineCode: |
var aws = require('aws-sdk');
var response = require('cfn-response');
exports.handler = function(event, context) {
// For Delete requests, immediately send a SUCCESS response.
if (event.RequestType == "Delete") {
response.send(event, context, "SUCCESS");
return;
}
var responseStatus = "FAILED";
var responseData = {};
var functionName = event.ResourceProperties.FunctionName
var lambda = new aws.Lambda();
lambda.invoke({ FunctionName: functionName }, function(err, invokeResult) {
if (err) {
responseData = {Error: "Invoke call failed"};
console.log(responseData.Error + ":\n", err);
}
else responseStatus = "SUCCESS";
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudformation.md
|
d7ce4dcebefd-5
|
console.log(responseData.Error + ":\n", err);
}
else responseStatus = "SUCCESS";
response.send(event, context, responseStatus, responseData);
});
};
Description: Invoke a function to create a log stream.
MemorySize: 128
Timeout: 8
Role: !GetAtt role.Arn
Tracing: Active
```
If the function that the custom resource invokes isn't defined in a template, you can get the source code for `cfn-response` from [cfn\-response module](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-lambda-function-code-cfnresponsemodule.html) in the AWS CloudFormation User Guide\.
For a sample application that uses a custom resource to ensure that a function's log group is created before another resource that depends on it, see [Error processor sample application for AWS Lambda](samples-errorprocessor.md)\.
For more information about custom resources, see [Custom resources](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html) in the *AWS CloudFormation User Guide*\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/services-cloudformation.md
|
eb3e77712393-0
|
The function's AWS X\-Ray tracing configuration\. To sample and record incoming requests, set `Mode` to `Active`\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_TracingConfig.md
|
b8c98eda88ac-0
|
**Mode** <a name="SSS-Type-TracingConfig-Mode"></a>
The tracing mode\.
Type: String
Valid Values:` Active | PassThrough`
Required: No
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_TracingConfig.md
|
af446b84f768-0
|
For more information about using this API in one of the language\-specific AWS SDKs, see the following:
+ [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/lambda-2015-03-31/TracingConfig)
+ [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/lambda-2015-03-31/TracingConfig)
+ [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/lambda-2015-03-31/TracingConfig)
+ [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/lambda-2015-03-31/TracingConfig)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_TracingConfig.md
|
6a8e1a195fa4-0
|
Several AWS services, such as Amazon Simple Storage Service \(Amazon S3\) and Amazon Simple Notification Service \(Amazon SNS\), invoke functions asynchronously to process events\. When you invoke a function asynchronously, you don't wait for a response from the function code\. You hand off the event to Lambda and Lambda handles the rest\. You can configure how Lambda handles errors, and can send invocation records to a downstream resource to chain together components of your application\.
The following diagram shows clients invoking a Lambda function asynchronously\. Lambda queues the events before sending them to the function\.
![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-async.png)
For asynchronous invocation, Lambda places the event in a queue and returns a success response without additional information\. A separate process reads events from the queue and sends them to your function\. To invoke a function asynchronously, set the invocation type parameter to `Event`\.
```
$ aws lambda invoke --function-name my-function --invocation-type Event --payload '{ "key": "value" }' response.json
{
"StatusCode": 202
}
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
6a8e1a195fa4-1
|
{
"StatusCode": 202
}
```
The output file \(`response.json`\) doesn't contain any information, but is still created when you run this command\. If Lambda isn't able to add the event to the queue, the error message appears in the command output\.
Lambda manages the function's asynchronous event queue and attempts to retry on errors\. If the function returns an error, Lambda attempts to run it two more times, with a one\-minute wait between the first two attempts, and two minutes between the second and third attempts\. Function errors include errors returned by the function's code and errors returned by the function's runtime, such as timeouts\.
![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/invocation-types-retries.png)
If the function doesn't have enough concurrency available to process all events, additional requests are throttled\. For throttling errors \(429\) and system errors \(500\-series\), Lambda returns the event to the queue and attempts to run the function again for up to 6 hours\. The retry interval increases exponentially from 1 second after the first attempt to a maximum of 5 minutes\. However, it might be longer if the queue is backed up\. Lambda also reduces the rate at which it reads events from the queue\.
The following example shows an event that was successfully added to the queue, but is still pending one hour later due to throttling\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
6a8e1a195fa4-2
|
The following example shows an event that was successfully added to the queue, but is still pending one hour later due to throttling\.
![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/invocation-types-throttle.png)
Even if your function doesn't return an error, it's possible for it to receive the same event from Lambda multiple times because the queue itself is eventually consistent\. If the function can't keep up with incoming events, events might also be deleted from the queue without being sent to the function\. Ensure that your function code gracefully handles duplicate events, and that you have enough concurrency available to handle all invocations\.
When the queue is backed up, new events might age out before Lambda has a chance to send them to your function\. When an event expires or fails all processing attempts, Lambda discards it\. You can [configure error handling](#invocation-async-errors) for a function to reduce the number of retries that Lambda performs, or to discard unprocessed events more quickly\.
You can also configure Lambda to send an invocation record to another service\. Lambda supports the following [destinations](#invocation-async-destinations) for asynchronous invocation\.
+ **Amazon SQS** β A standard SQS queue\.
+ **Amazon SNS** β An SNS topic\.
+ **AWS Lambda** β A Lambda function\.
+ **Amazon EventBridge** β An EventBridge event bus\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
6a8e1a195fa4-3
|
+ **AWS Lambda** β A Lambda function\.
+ **Amazon EventBridge** β An EventBridge event bus\.
The invocation record contains details about the request and response in JSON format\. You can configure separate destinations for events that are processed successfully, and events that fail all processing attempts\. Alternatively, you can configure an SQS queue or SNS topic as a [dead\-letter queue](#dlq) for discarded events\. For dead\-letter queues, Lambda only sends the content of the event, without details about the response\.
**Topics**
+ [Configuring error handling for asynchronous invocation](#invocation-async-errors)
+ [Configuring destinations for asynchronous invocation](#invocation-async-destinations)
+ [Asynchronous invocation configuration API](#invocation-async-api)
+ [AWS Lambda function dead\-letter queues](#dlq)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
8aa24aef31cc-0
|
Use the Lambda console to configure error handling settings on a function, a version, or an alias\.
**To configure error handling**
1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\.
1. Choose a function\.
1. Under **Asynchronous invocation**, choose **Edit**\.
1. Configure the following settings\.
+ **Maximum age of event** β The maximum amount of time Lambda retains an event in the asynchronous event queue, up to 6 hours\.
+ **Retry attempts** β The number of times Lambda retries when the function returns an error, between 0 and 2\.
1. Choose **Save**\.
When an invocation event exceeds the maximum age or fails all retry attempts, Lambda discards it\. To retain a copy of discarded events, configure a failed\-event destination\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
7e7ae808d5a3-0
|
To send records of asynchronous invocations to another service, add a destination to your function\. You can configure separate destinations for events that fail processing and events that are successfully processed\. Like error handling settings, you can configure destinations on a function, a version, or an alias\.
The following example shows a function that is processing asynchronous invocations\. When the function returns a success response or exits without throwing an error, Lambda sends a record of the invocation to an EventBridge event bus\. When an event fails all processing attempts, Lambda sends an invocation record to an Amazon SQS queue\.
![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/features-destinations.png)
To send events to a destination, your function needs additional permissions\. Add a policy with the required permissions to your function's [execution role](lambda-intro-execution-role.md)\. 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/invocation-async.md
|
7e7ae808d5a3-1
|
+ **Lambda** β [lambda:InvokeFunction](https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html)
+ **EventBridge** β [events:PutEvents](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_PutEvents.html)
Add destinations to your function in the Lambda console's function designer\.
**To configure a destination for asynchronous invocation 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**\.
1. For **Source**, choose **Asynchronous invocation**\.
1. For **Condition**, choose from the following options:
+ **On failure** β Send a record when the event fails all processing attempts or exceeds the maximum age\.
+ **On success** β Send a record when the function successfully processes an asynchronous invocation\.
1. For **Destination type**, choose the type of resource that receives the invocation record\.
1. For **Destination**, choose a resource\.
1. Choose **Save**\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
7e7ae808d5a3-2
|
1. For **Destination**, choose a resource\.
1. Choose **Save**\.
When an invocation matches the condition, Lambda sends a JSON document with details about the invocation to the destination\. The following example shows an invocation record for an event that failed three processing attempts due to a function error\.
**Example invocation record**
```
{
"version": "1.0",
"timestamp": "2019-11-14T18:16:05.568Z",
"requestContext": {
"requestId": "e4b46cbf-b738-xmpl-8880-a18cdf61200e",
"functionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function:$LATEST",
"condition": "RetriesExhausted",
"approximateInvokeCount": 3
},
"requestPayload": {
"ORDER_IDS": [
"9e07af03-ce31-4ff3-xmpl-36dce652cb4f",
"637de236-e7b2-464e-xmpl-baf57f86bb53",
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
7e7ae808d5a3-3
|
"637de236-e7b2-464e-xmpl-baf57f86bb53",
"a81ddca6-2c35-45c7-xmpl-c3a03a31ed15"
]
},
"responseContext": {
"statusCode": 200,
"executedVersion": "$LATEST",
"functionError": "Unhandled"
},
"responsePayload": {
"errorMessage": "RequestId: e4b46cbf-b738-xmpl-8880-a18cdf61200e Process exited before completing request"
}
}
```
The invocation record contains details about the event, the response, and the reason that the record was sent\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
26f6aa713cd5-0
|
To manage asynchronous invocation settings with the AWS CLI or AWS SDK, use the following API operations\.
+ [PutFunctionEventInvokeConfig](https://docs.aws.amazon.com/lambda/latest/dg/API_PutFunctionEventInvokeConfig.html)
+ [GetFunctionEventInvokeConfig](https://docs.aws.amazon.com/lambda/latest/dg/API_GetFunctionEventInvokeConfig.html)
+ [UpdateFunctionEventInvokeConfig](https://docs.aws.amazon.com/lambda/latest/dg/API_UpdateFunctionEventInvokeConfig.html)
+ [ListFunctionEventInvokeConfigs](https://docs.aws.amazon.com/lambda/latest/dg/API_ListFunctionEventInvokeConfigs.html)
+ [DeleteFunctionEventInvokeConfig](https://docs.aws.amazon.com/lambda/latest/dg/API_DeleteFunctionEventInvokeConfig.html)
To configure asynchronous invocation with the AWS CLI, use the `put-function-event-invoke-config` command\. The following example configures a function with a maximum event age of 1 hour and no retries\.
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
26f6aa713cd5-1
|
```
$ aws lambda put-function-event-invoke-config --function-name error \
--maximum-event-age-in-seconds 3600 --maximum-retry-attempts 0
{
"LastModified": 1573686021.479,
"FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:error:$LATEST",
"MaximumRetryAttempts": 0,
"MaximumEventAgeInSeconds": 3600,
"DestinationConfig": {
"OnSuccess": {},
"OnFailure": {}
}
}
```
The `put-function-event-invoke-config` command overwrites any existing configuration on the function, version, or alias\. To configure an option without resetting others, use `update-function-event-invoke-config`\. The following example configures Lambda to send a record to an SQS queue named `destination` when an event can't be processed\.
```
$ aws lambda update-function-event-invoke-config --function-name error \
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
26f6aa713cd5-2
|
```
$ aws lambda update-function-event-invoke-config --function-name error \
--destination-config '{"OnFailure":{"Destination": "arn:aws:sqs:us-east-2:123456789012:destination"}}'
{
"LastModified": 1573687896.493,
"FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:error:$LATEST",
"MaximumRetryAttempts": 0,
"MaximumEventAgeInSeconds": 3600,
"DestinationConfig": {
"OnSuccess": {},
"OnFailure": {
"Destination": "arn:aws:sqs:us-east-2:123456789012:destination"
}
}
}
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
b177b0b70ff9-0
|
As an alternative to an [on\-failure destination](#invocation-async-destinations), you can configure your function with a dead\-letter queue to save discarded events for further processing\. A dead\-letter queue acts the same as an on\-failure destination in that it is used when an event fails all processing attempts or expires without being processed\. However, a dead\-letter queue is part of a function's version\-specific configuration, so it is locked in when you publish a version\. On\-failure destinations also support additional targets and include details about the function's response in the invocation record\.
If you don't have a queue or topic, create one\. Choose the target type that matches your use case\.
+ [Amazon SQS queue](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-create-queue.html) β A queue holds failed events until they're retrieved\. You can retrieve events manually, or you can [configure Lambda to read from the queue](with-sqs.md) and invoke a function\.
Create a queue in the [Amazon SQS console](https://console.aws.amazon.com/sqs)\.
+ [Amazon SNS topic](https://docs.aws.amazon.com/sns/latest/gsg/CreateTopic.html) β A topic relays failed events to one or more destinations\. You can configure a topic to send events to an email address, a Lambda function, or an HTTP endpoint\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
b177b0b70ff9-1
|
Create a topic in the [Amazon SNS console](https://console.aws.amazon.com/sns/home)\.
To send events to a queue or topic, your function needs additional permissions\. Add a policy with the required permissions to your function's [execution role](lambda-intro-execution-role.md)\.
+ **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)
If the target queue or topic is encrypted with a customer managed key, the execution role must also be a user in the key's [resource\-based policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html)\.
After creating the target and updating your function's execution role, add the dead\-letter queue to your function\. You can configure multiple functions to send events to the same target\.
**To configure a dead\-letter queue**
1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\.
1. Choose a function\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
b177b0b70ff9-2
|
1. Choose a function\.
1. Under **Asynchronous invocation**, choose **Edit**\.
1. Set **DLQ resource** to **Amazon SQS** or **Amazon SNS**\.
1. Choose the target queue or topic\.
1. Choose **Save**\.
To configure a dead\-letter queue with the AWS CLI, use the `update-function-configuration` command\.
```
$ aws lambda update-function-configuration --function-name my-function \
--dead-letter-config TargetArn=arn:aws:sns:us-east-2:123456789012:my-topic
```
Lambda sends the event to the dead\-letter queue as\-is, with additional information in attributes\. You can use this information to identify the error that the function returned, or to correlate the event with logs or an AWS X\-Ray trace\.
**Dead\-letter queue message attributes**
+ **RequestID** \(String\) β The ID of the invocation request\. Request IDs appear in function logs\. You can also use the X\-Ray SDK to record the request ID on an attribute in the trace\. You can then search for traces by request ID in the X\-Ray console\. For an example, see the [error processor sample](samples-errorprocessor.md)\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
b177b0b70ff9-3
|
+ **ErrorCode** \(Number\) β The HTTP status code\.
+ **ErrorMessage** \(String\) β The first 1 KB of the error message\.
![\[\]](http://docs.aws.amazon.com/lambda/latest/dg/images/invocation-dlq-attributes.png)
If Lambda can't send a message to the dead\-letter queue, it deletes the event and emits the [DeadLetterErrors](monitoring-metrics.md) metric\. This can happen because of lack of permissions, or if the total size of the message exceeds the limit for the target queue or topic\. For example, if an Amazon SNS notification with a body close to 256 KB triggers a function that results in an error, the additional event data added by Amazon SNS, combined with the attributes added by Lambda, can cause the message to exceed the maximum size allowed in the dead\-letter queue\.
If you're using Amazon SQS as an event source, configure a dead\-letter queue on the Amazon SQS queue itself and not on the Lambda function\. For more information, see [Using AWS Lambda with Amazon SQS](with-sqs.md)\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/invocation-async.md
|
54fa0cb0dace-0
|
Returns details about an event source mapping\. You can get the identifier of a mapping from the output of [ListEventSourceMappings](API_ListEventSourceMappings.md)\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
7a1802018638-0
|
```
GET /2015-03-31/event-source-mappings/UUID HTTP/1.1
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
b68a1d4313fc-0
|
The request uses the following URI parameters\.
** [UUID](#API_GetEventSourceMapping_RequestSyntax) ** <a name="SSS-GetEventSourceMapping-request-UUID"></a>
The identifier of the event source mapping\.
Required: Yes
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
51a1fa69e702-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_GetEventSourceMapping.md
|
132bab5e6474-0
|
```
HTTP/1.1 200
Content-type: application/json
{
"BatchSize": number,
"BisectBatchOnFunctionError": boolean,
"DestinationConfig": {
"OnFailure": {
"Destination": "string"
},
"OnSuccess": {
"Destination": "string"
}
},
"EventSourceArn": "string",
"FunctionArn": "string",
"LastModified": number,
"LastProcessingResult": "string",
"MaximumBatchingWindowInSeconds": number,
"MaximumRecordAgeInSeconds": number,
"MaximumRetryAttempts": number,
"ParallelizationFactor": number,
"State": "string",
"StateTransitionReason": "string",
"Topics": [ "string" ],
"UUID": "string"
}
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
19da3804c115-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\.
** [BatchSize](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-BatchSize"></a>
The maximum number of items to retrieve in a single batch\.
Type: Integer
Valid Range: Minimum value of 1\. Maximum value of 10000\.
** [BisectBatchOnFunctionError](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-BisectBatchOnFunctionError"></a>
\(Streams\) If the function returns an error, split the batch in two and retry\. The default value is false\.
Type: Boolean
** [DestinationConfig](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-DestinationConfig"></a>
\(Streams\) An Amazon SQS queue or Amazon SNS topic destination for discarded records\.
Type: [DestinationConfig](API_DestinationConfig.md) object
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
19da3804c115-1
|
Type: [DestinationConfig](API_DestinationConfig.md) object
** [EventSourceArn](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-EventSourceArn"></a>
The Amazon Resource Name \(ARN\) of the event source\.
Type: String
Pattern: `arn:(aws[a-zA-Z0-9-]*):([a-zA-Z0-9\-])+:([a-z]{2}(-gov)?-[a-z]+-\d{1})?:(\d{12})?:(.*)`
** [FunctionArn](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-FunctionArn"></a>
The ARN of the Lambda function\.
Type: String
Pattern: `arn:(aws[a-zA-Z-]*)?:lambda:[a-z]{2}(-gov)?-[a-z]+-\d{1}:\d{12}:function:[a-zA-Z0-9-_]+(:(\$LATEST|[a-zA-Z0-9-_]+))?`
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
19da3804c115-2
|
** [LastModified](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-LastModified"></a>
The date that the event source mapping was last updated, or its state changed, in Unix time seconds\.
Type: Timestamp
** [LastProcessingResult](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-LastProcessingResult"></a>
The result of the last AWS Lambda invocation of your Lambda function\.
Type: String
** [MaximumBatchingWindowInSeconds](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-MaximumBatchingWindowInSeconds"></a>
\(Streams\) The maximum amount of time to gather records before invoking the function, in seconds\. The default value is zero\.
Type: Integer
Valid Range: Minimum value of 0\. Maximum value of 300\.
** [MaximumRecordAgeInSeconds](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-MaximumRecordAgeInSeconds"></a>
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
19da3804c115-3
|
\(Streams\) Discard records older than the specified age\. The default value is infinite \(\-1\)\. When set to infinite \(\-1\), failed records are retried until the record expires\.
Type: Integer
Valid Range: Minimum value of 60\. Maximum value of 604800\.
** [MaximumRetryAttempts](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-MaximumRetryAttempts"></a>
\(Streams\) Discard records after the specified number of retries\. The default value is infinite \(\-1\)\. When set to infinite \(\-1\), failed records are retried until the record expires\.
Type: Integer
Valid Range: Minimum value of 0\. Maximum value of 10000\.
** [ParallelizationFactor](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-ParallelizationFactor"></a>
\(Streams\) The number of batches to process from each shard concurrently\. The default value is 1\.
Type: Integer
Valid Range: Minimum value of 1\. Maximum value of 10\.
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
19da3804c115-4
|
Type: Integer
Valid Range: Minimum value of 1\. Maximum value of 10\.
** [State](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-State"></a>
The state of the event source mapping\. It can be one of the following: `Creating`, `Enabling`, `Enabled`, `Disabling`, `Disabled`, `Updating`, or `Deleting`\.
Type: String
** [StateTransitionReason](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-StateTransitionReason"></a>
Indicates whether the last change to the event source mapping was made by a user, or by the Lambda service\.
Type: String
** [Topics](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-Topics"></a>
\(MSK\) The name of the Kafka topic\.
Type: Array of strings
Array Members: Fixed number of 1 item\.
Length Constraints: Minimum length of 1\. Maximum length of 249\.
Pattern: `^[^.]([a-zA-Z0-9\-_.]+)`
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
19da3804c115-5
|
Pattern: `^[^.]([a-zA-Z0-9\-_.]+)`
** [UUID](#API_GetEventSourceMapping_ResponseSyntax) ** <a name="SSS-GetEventSourceMapping-response-UUID"></a>
The identifier of the event source mapping\.
Type: String
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
14e7daf08fe4-0
|
**InvalidParameterValueException**
One of the parameters in the request is invalid\.
HTTP Status Code: 400
**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_GetEventSourceMapping.md
|
9e942fb100f9-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/GetEventSourceMapping)
+ [AWS SDK for \.NET](https://docs.aws.amazon.com/goto/DotNetSDKV3/lambda-2015-03-31/GetEventSourceMapping)
+ [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/lambda-2015-03-31/GetEventSourceMapping)
+ [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/lambda-2015-03-31/GetEventSourceMapping)
+ [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/lambda-2015-03-31/GetEventSourceMapping)
+ [AWS SDK for JavaScript](https://docs.aws.amazon.com/goto/AWSJavaScriptSDK/lambda-2015-03-31/GetEventSourceMapping)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
9e942fb100f9-1
|
+ [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/lambda-2015-03-31/GetEventSourceMapping)
+ [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/lambda-2015-03-31/GetEventSourceMapping)
+ [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/lambda-2015-03-31/GetEventSourceMapping)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_GetEventSourceMapping.md
|
4a64686e0b1a-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 [the fmt package](https://golang.org/pkg/fmt/), or any logging library that writes to `stdout` or `stderr`\. The following example uses [the log package](https://golang.org/pkg/log/)\.
**Example [main\.go](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/blank-go/function/main.go) β Logging**
```
func handleRequest(ctx context.Context, event events.SQSEvent) (string, error) {
// event
eventJson, _ := json.MarshalIndent(event, "", " ")
log.Printf("EVENT: %s", eventJson)
// environment variables
log.Printf("REGION: %s", os.Getenv("AWS_REGION"))
log.Println("ALL ENV VARS:")
for _, element := range os.Environ() {
log.Println(element)
}
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/golang-logging.md
|
4a64686e0b1a-1
|
for _, element := range os.Environ() {
log.Println(element)
}
```
**Example log format**
```
START RequestId: dbda340c-xmpl-4031-8810-11bb609b4c71 Version: $LATEST
2020/03/27 03:40:05 EVENT: {
"Records": [
{
"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
"receiptHandle": "MessageReceiptHandle",
"body": "Hello from SQS!",
"md5OfBody": "7b27xmplb47ff90a553787216d55d91d",
"md5OfMessageAttributes": "",
"attributes": {
"ApproximateFirstReceiveTimestamp": "1523232000001",
"ApproximateReceiveCount": "1",
"SenderId": "123456789012",
"SentTimestamp": "1523232000000"
},
...
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/golang-logging.md
|
4a64686e0b1a-2
|
"SentTimestamp": "1523232000000"
},
...
2020/03/27 03:40:05 AWS_LAMBDA_LOG_STREAM_NAME=2020/03/27/[$LATEST]569cxmplc3c34c7489e6a97ad08b4419
2020/03/27 03:40:05 AWS_LAMBDA_FUNCTION_NAME=blank-go-function-9DV3XMPL6XBC
2020/03/27 03:40:05 AWS_LAMBDA_FUNCTION_MEMORY_SIZE=128
2020/03/27 03:40:05 AWS_LAMBDA_FUNCTION_VERSION=$LATEST
2020/03/27 03:40:05 AWS_EXECUTION_ENV=AWS_Lambda_go1.x
END RequestId: dbda340c-xmpl-4031-8810-11bb609b4c71
REPORT RequestId: dbda340c-xmpl-4031-8810-11bb609b4c71 Duration: 38.66 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 54 MB Init Duration: 203.69 ms
XRAY TraceId: 1-5e7d7595-212fxmpl9ee07c4884191322 SegmentId: 42ffxmpl0645f474 Sampled: true
```
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/golang-logging.md
|
4a64686e0b1a-3
|
```
The Go 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\.
+ **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](#golang-logging-console)
+ [Using the AWS CLI](#golang-logging-cli)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/golang-logging.md
|
4a64686e0b1a-4
|
+ [Using the AWS CLI](#golang-logging-cli)
+ [Deleting logs](#golang-logging-delete)
|
https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/golang-logging.md
|
c12f66819956-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/golang-logging.md
|
cc3c4bc705ac-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/golang-logging.md
|
cc3c4bc705ac-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/golang-logging.md
|
cc3c4bc705ac-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/golang-logging.md
|
cc3c4bc705ac-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/golang-logging.md
|
cc3c4bc705ac-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/golang-logging.md
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.