Skip to content

Commit bc2b389

Browse files
committed
sample apps, logging, .NET Core 3.1
1 parent e8d13db commit bc2b389

29 files changed

+340
-336
lines changed

doc_source/applications-tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ Create an application in the Lambda console\.
6060
+ **Application name****my\-app**\.
6161
+ **Application description****my application**\.
6262
+ **Runtime****Node\.js 10\.x**\.
63-
+ **Repository provider****CodeCommit**\.
64-
+ **Repository provider****my\-app\-repo**\.
63+
+ **Source control service****CodeCommit**\.
64+
+ **Repository name****my\-app\-repo**\.
6565
+ **Permissions****Create roles and permissions boundary**\.
6666

6767
1. Choose **Create**\.

doc_source/configuration-database.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Configuring Database Access for a Lambda Function<a name="configuration-database"></a>
22

3-
You can use the Lambda console to create an Amazon Relational Database Service \(Amazon RDS\) database proxy for your function\. A database proxy manages a pool of database connections and relays queries from a function\. This enables a function to reach high [concurrency](gettingstarted-concepts.md#gettingstarted-concepts-concurrency) levels without exhausting database connections\.
3+
You can use the Lambda console to create an Amazon RDS Proxy database proxy for your function\. A database proxy manages a pool of database connections and relays queries from a function\. This enables a function to reach high [concurrency](gettingstarted-concepts.md#gettingstarted-concepts-concurrency) levels without exhausting database connections\.
44

55
**To create a database proxy**
66

@@ -28,7 +28,7 @@ You can use the Lambda console to create an Amazon Relational Database Service \
2828

2929
Proxy creation takes a few minutes\. When the proxy is available, configure your function to connect to the proxy endpoint instead of the database endpoint\.
3030

31-
For more information, see [Managing Connections with the Amazon RDS Proxy](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/rds-proxy.html) in the Amazon Aurora User Guide\.
31+
Standard [Amazon RDS Proxy pricing](https://aws.amazon.com/rds/proxy/pricing/) applies\. For more information, see [Managing Connections with the Amazon RDS Proxy](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/rds-proxy.html) in the Amazon Aurora User Guide\.
3232

3333
## Sample Application<a name="configuration-database-sample"></a>
3434

doc_source/csharp-logging.md

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,65 @@
22

33
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\.
44

5-
To output logs from your function code, you can use methods on [the Console class](https://docs.microsoft.com/en-us/dotnet/api/system.console), or any logging library that writes to `stdout` or `stderr`\. The following example logs the request ID for an invocation\.
5+
To output logs from your function code, you can use methods on [the Console class](https://docs.microsoft.com/en-us/dotnet/api/system.console), or any logging library that writes to `stdout` or `stderr`\. The following example uses the `LambdaLogger` class from the [Amazon\.Lambda\.Core](lambda-csharp.md) library\.
6+
7+
**Example [src/blank\-csharp/Function\.cs](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/blank-csharp/src/blank-csharp/Function.cs) – logging**
68

79
```
8-
public class ProductService
9-
{
10-
public async Task<Product> DescribeProduct(DescribeProductRequest request)
10+
public async Task<AccountUsage> FunctionHandler(SQSEvent invocationEvent, ILambdaContext context)
1111
{
12-
Console.WriteLine("DescribeProduct invoked with Id " + request.Id);
13-
return await catalogService.DescribeProduct(request.Id);
12+
GetAccountSettingsResponse accountSettings;
13+
try
14+
{
15+
accountSettings = await callLambda();
16+
}
17+
catch (AmazonLambdaException ex)
18+
{
19+
throw ex;
20+
}
21+
AccountUsage accountUsage = accountSettings.AccountUsage;
22+
LambdaLogger.Log("ENVIRONMENT VARIABLES: " + JsonConvert.SerializeObject(System.Environment.GetEnvironmentVariables()));
23+
LambdaLogger.Log("CONTEXT: " + JsonConvert.SerializeObject(context));
24+
LambdaLogger.Log("EVENT: " + JsonConvert.SerializeObject(invocationEvent));
25+
return accountUsage;
1426
}
15-
}
1627
```
1728

18-
Lambda also provides a logger class in the `Amazon.Lambda.Core ` library\. Use the `Log` method on the `Amazon.Lambda.Core.LambdaLogger` class to write logs\.
29+
**Example Log Format**
1930

2031
```
21-
using Amazon.Lambda.Core;
22-
23-
public class ProductService
32+
START RequestId: d1cf0ccb-xmpl-46e6-950d-04c96c9b1c5d Version: $LATEST
33+
ENVIRONMENT VARIABLES:
2434
{
25-
public async Task<Product> DescribeProduct(DescribeProductRequest request)
26-
{
27-
LambdaLogger.Log("DescribeProduct invoked with Id " + request.Id);
28-
return await catalogService.DescribeProduct(request.Id);
29-
}
30-
}
31-
```
32-
33-
An instance of this class is also available on [the context object](csharp-context.md)\.
34-
35-
```
36-
public class ProductService
35+
"AWS_EXECUTION_ENV": "AWS_Lambda_dotnetcore2.1",
36+
"AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "256",
37+
"AWS_LAMBDA_LOG_GROUP_NAME": "/aws/lambda/blank-csharp-function-WU56XMPLV2XA",
38+
"AWS_LAMBDA_FUNCTION_VERSION": "$LATEST",
39+
"AWS_LAMBDA_LOG_STREAM_NAME": "2020/03/27/[$LATEST]5296xmpl084f411d9fb73b258393f30c",
40+
"AWS_LAMBDA_FUNCTION_NAME": "blank-csharp-function-WU56XMPLV2XA",
41+
...
42+
EVENT:
3743
{
38-
public async Task<Product> DescribeProduct(DescribeProductRequest request, ILambdaContext context)
39-
{
40-
context.Logger.Log("DescribeProduct invoked with Id " + request.Id);
41-
return await catalogService.DescribeProduct(request.Id);
42-
}
43-
}
44-
```
45-
46-
**Example Log Format**
47-
48-
```
49-
START RequestId: 29d229ff-xmpl-49d8-8d86-b1f89b06bdc9 Version: $LATEST
50-
END RequestId: 29d229ff-xmpl-49d8-8d86-b1f89b06bdc9
51-
REPORT RequestId: 29d229ff-xmpl-49d8-8d86-b1f89b06bdc9 Duration: 576.36 ms Billed Duration: 600 ms Memory Size: 512 MB Max Memory Used: 69 MB Init Duration: 205.64 ms
52-
XRAY TraceId: 1-5e34a44f-a125xmpl3603a4cdf526103e SegmentId: 5f41xmpl4b1664d9 Sampled: true
44+
"Records": [
45+
{
46+
"MessageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
47+
"ReceiptHandle": "MessageReceiptHandle",
48+
"Body": "Hello from SQS!",
49+
"Md5OfBody": "7b270e59b47ff90a553787216d55d91d",
50+
"Md5OfMessageAttributes": null,
51+
"EventSourceArn": "arn:aws:sqs:us-west-2:123456789012:MyQueue",
52+
"EventSource": "aws:sqs",
53+
"AwsRegion": "us-west-2",
54+
"Attributes": {
55+
"ApproximateReceiveCount": "1",
56+
"SentTimestamp": "1523232000000",
57+
"SenderId": "123456789012",
58+
"ApproximateFirstReceiveTimestamp": "1523232000001"
59+
},
60+
...
61+
END RequestId: d1cf0ccb-xmpl-46e6-950d-04c96c9b1c5d
62+
REPORT RequestId: d1cf0ccb-xmpl-46e6-950d-04c96c9b1c5d Duration: 4157.16 ms Billed Duration: 4200 ms Memory Size: 256 MB Max Memory Used: 99 MB Init Duration: 841.60 ms
63+
XRAY TraceId: 1-5e7e8131-7ff0xmpl32bfb31045d0a3bb SegmentId: 0152xmpl6016310f Sampled: true
5364
```
5465

5566
The \.NET runtime logs the `START`, `END`, and `REPORT` lines for each invocation\. The report line provides the following details\.

doc_source/csharp-package-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Under the `src/myfunction` directory, examine the following files:
5454
"region" : "us-east-2",
5555
"configuration" : "Release",
5656
"framework" : "netcoreapp2.1",
57-
"function-runtime":"dotnetcore2.1",
57+
"function-runtime":"dotnetcore3.1",
5858
"function-memory-size" : 256,
5959
"function-timeout" : 30,
6060
"function-handler" : "MyFunction::MyFunction.Function::FunctionHandler"

doc_source/csharp-package-toolkit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ You can build \.NET\-based Lambda applications using the Lambda plugin to the [A
2222
"region" : "us-east-2",
2323
"configuration" : "Release",
2424
"framework" : "netcoreapp2.1",
25-
"function-runtime":"dotnetcore2.1",
25+
"function-runtime":"dotnetcore3.1",
2626
"function-memory-size" : 256,
2727
"function-timeout" : 30,
2828
"function-handler" : "Assembly::Namespace.Class::Function"

doc_source/gettingstarted-limits.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ The following limits apply to function configuration, deployments, and execution
2222
| Function [resource\-based policy](access-control-resource-based.md) | 20 KB |
2323
| Function [layers](configuration-layers.md) | 5 layers |
2424
| Function [burst concurrency](invocation-scaling.md) | 500 \- 3000 \([varies per region](invocation-scaling.md)\) |
25-
| Invocation frequency \(requests per second\) | 10 x concurrent executions limit \([synchronous](invocation-sync.md) – all sources\) 10 x concurrent executions limit \([asynchronous](invocation-async.md) – non\-AWS sources\) Unlimited \(asynchronous – [AWS service sources](lambda-services.md)\) |
25+
| Invocation frequency per Region \(requests per second\) | 10 x concurrent executions limit \([synchronous](invocation-sync.md) – all sources\) 10 x concurrent executions limit \([asynchronous](invocation-async.md) – non\-AWS sources\) Unlimited \(asynchronous – [AWS service sources](lambda-services.md)\) |
26+
| Invocation frequency per function version or alias \(requests per second\) | 10 x allocated [provisioned concurrency](configuration-concurrency.md) This limit only applies to functions that use provisioned concurrency\. |
2627
| [Invocation payload](lambda-invocation.md) \(request and response\) | 6 MB \(synchronous\) 256 KB \(asynchronous\) |
2728
| [Deployment package](gettingstarted-features.md#gettingstarted-features-package) size | 50 MB \(zipped, for direct upload\) 250 MB \(unzipped, including layers\) 3 MB \(console editor\) |
2829
| Test events \(console editor\) | 10 |

doc_source/golang-logging.md

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,50 @@
22

33
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\.
44

5-
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 `fmt.Print`\.
5+
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/)\.
66

7-
```
8-
package main
9-
10-
import (
11-
"fmt"
12-
"github.com/aws/aws-lambda-go/lambda"
13-
)
14-
15-
func HandleRequest() {
16-
fmt.Print("Hello from Lambda")
17-
}
18-
19-
func main() {
20-
lambda.Start(HandleRequest)
21-
}
22-
```
23-
24-
For more detailed logs, use [the log package](https://golang.org/pkg/log/)\.
7+
**Example [main\.go](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/blank-go/function/main.go) – logging**
258

269
```
27-
package main
28-
29-
import (
30-
"log"
31-
"github.com/aws/aws-lambda-go/lambda"
32-
)
33-
34-
func HandleRequest() {
35-
log.Print("Event received.")
36-
}
37-
38-
func main() {
39-
lambda.Start(HandleRequest)
40-
}
10+
func handleRequest(ctx context.Context, event events.SQSEvent) (string, error) {
11+
// event
12+
eventJson, _ := json.MarshalIndent(event, "", " ")
13+
log.Printf("EVENT: %s", eventJson)
14+
// environment variables
15+
log.Printf("REGION: %s", os.Getenv("AWS_REGION"))
16+
log.Println("ALL ENV VARS:")
17+
for _, element := range os.Environ() {
18+
log.Println(element)
19+
}
4120
```
4221

4322
**Example Log Format**
4423

4524
```
46-
START RequestId: 6b9702a6-xmpl-487a-a10d-b066d7e8a5e1 Version: $LATEST
47-
END RequestId: 6b9702a6-xmpl-487a-a10d-b066d7e8a5e1
48-
REPORT RequestId: 6b9702a6-xmpl-487a-a10d-b066d7e8a5e1 Duration: 1.07 ms Billed Duration: 100 ms Memory Size: 512 MB Max Memory Used: 41 MB Init Duration: 204.69 ms
49-
XRAY TraceId: 1-5e34a425-4b30xmple305c998ac423ea5 SegmentId: 6362xmpl0ff64446 Sampled: true
25+
START RequestId: dbda340c-xmpl-4031-8810-11bb609b4c71 Version: $LATEST
26+
2020/03/27 03:40:05 EVENT: {
27+
"Records": [
28+
{
29+
"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
30+
"receiptHandle": "MessageReceiptHandle",
31+
"body": "Hello from SQS!",
32+
"md5OfBody": "7b27xmplb47ff90a553787216d55d91d",
33+
"md5OfMessageAttributes": "",
34+
"attributes": {
35+
"ApproximateFirstReceiveTimestamp": "1523232000001",
36+
"ApproximateReceiveCount": "1",
37+
"SenderId": "123456789012",
38+
"SentTimestamp": "1523232000000"
39+
},
40+
...
41+
2020/03/27 03:40:05 AWS_LAMBDA_LOG_STREAM_NAME=2020/03/27/[$LATEST]569cxmplc3c34c7489e6a97ad08b4419
42+
2020/03/27 03:40:05 AWS_LAMBDA_FUNCTION_NAME=blank-go-function-9DV3XMPL6XBC
43+
2020/03/27 03:40:05 AWS_LAMBDA_FUNCTION_MEMORY_SIZE=128
44+
2020/03/27 03:40:05 AWS_LAMBDA_FUNCTION_VERSION=$LATEST
45+
2020/03/27 03:40:05 AWS_EXECUTION_ENV=AWS_Lambda_go1.x
46+
END RequestId: dbda340c-xmpl-4031-8810-11bb609b4c71
47+
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
48+
XRAY TraceId: 1-5e7d7595-212fxmpl9ee07c4884191322 SegmentId: 42ffxmpl0645f474 Sampled: true
5049
```
5150

5251
The Go runtime logs the `START`, `END`, and `REPORT` lines for each invocation\. The report line provides the following details\.

doc_source/java-context.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ The GitHub repository for this guide includes sample applications that demonstra
100100

101101
**Java Sample Applications**
102102
+ [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\. Includes both Gradle and Maven builds\.
103+
+ [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 and Amazon Simple Notification Service\.
104+
+ [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\)\.
103105
+ [blank\-java](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-java) – A Java function with the events library, advanced logging configuration, and the AWS SDK for Java 2\.x that calls the Lambda API to retrieve account settings\.
104106
+ [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\.
105107

doc_source/java-exceptions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ The GitHub repository for this guide includes sample applications that demonstra
219219

220220
**Java Sample Applications**
221221
+ [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\. Includes both Gradle and Maven builds\.
222+
+ [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 and Amazon Simple Notification Service\.
223+
+ [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\)\.
222224
+ [blank\-java](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-java) – A Java function with the events library, advanced logging configuration, and the AWS SDK for Java 2\.x that calls the Lambda API to retrieve account settings\.
223225
+ [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\.
224226

doc_source/java-handler.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ The GitHub repository for this guide includes sample applications that demonstra
171171

172172
**Java Sample Applications**
173173
+ [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\. Includes both Gradle and Maven builds\.
174+
+ [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 and Amazon Simple Notification Service\.
175+
+ [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\)\.
174176
+ [blank\-java](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-java) – A Java function with the events library, advanced logging configuration, and the AWS SDK for Java 2\.x that calls the Lambda API to retrieve account settings\.
175177
+ [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\.
176178

doc_source/java-logging.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ The GitHub repository for this guide includes sample applications that demonstra
290290

291291
**Java Sample Applications**
292292
+ [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\. Includes both Gradle and Maven builds\.
293+
+ [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 and Amazon Simple Notification Service\.
294+
+ [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\)\.
293295
+ [blank\-java](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-java) – A Java function with the events library, advanced logging configuration, and the AWS SDK for Java 2\.x that calls the Lambda API to retrieve account settings\.
294296
+ [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\.
295297

0 commit comments

Comments
 (0)