Skip to content

Commit e99cacc

Browse files
committed
Add back original blank-csharp example, differentiate it from blank-csharp-with-layer, update README for new example with layer
1 parent c726a2b commit e99cacc

23 files changed

+383
-3
lines changed

.DS_Store

0 Bytes
Binary file not shown.

sample-apps/blank-csharp/1-create-bucket-and-role.sh renamed to sample-apps/blank-csharp-with-layer/1-create-bucket-and-role.sh

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Blank function with layer (C#)
2+
3+
![Architecture](/sample-apps/blank-csharp/images/sample-blank-csharp.png)
4+
5+
The project source includes function code and supporting resources:
6+
7+
- `src/blank-csharp` - A C# .NET Core function.
8+
- `1-create-bucket.sh`, `2-deploy.sh`, etc. - Shell scripts that use the AWS CLI to deploy and manage the application.
9+
10+
Use the following instructions to deploy the sample application. For more information on the application's architecture and implementation, see [Managing Spot Instance Requests](https://docs.aws.amazon.com/lambda/latest/dg/services-ec2-tutorial.html) in the developer guide.
11+
12+
# Requirements
13+
- [.NET Core SDK 6.0](https://dotnet.microsoft.com/download/dotnet-core/6.0)
14+
- [AWS extensions for .NET CLI](https://github.com/aws/aws-extensions-for-dotnet-cli). Specifically, ensure that you have [Amazon.Lambda.Tools](https://github.com/aws/aws-extensions-for-dotnet-cli#aws-lambda-amazonlambdatools) installed.
15+
- The Bash shell. For Linux and macOS, this is included by default. In Windows 10, you can install the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get a Windows-integrated version of Ubuntu and Bash.
16+
- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer.
17+
18+
If you use the AWS CLI v2, add the following to your [configuration file](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) (`~/.aws/config`):
19+
20+
```
21+
cli_binary_format=raw-in-base64-out
22+
```
23+
24+
This setting enables the AWS CLI v2 to load JSON events from a file, matching the v1 behavior.
25+
26+
# Setup
27+
Download or clone this repository.
28+
29+
$ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git
30+
$ cd aws-lambda-developer-guide/sample-apps/blank-csharp
31+
32+
To create a new bucket for deployment artifacts, run `1-create-bucket-and-role.sh`.
33+
34+
blank-csharp$ ./1-create-bucket.sh
35+
make_bucket: lambda-artifacts-d7aec9f2022ef2b4
36+
make_bucket: lambda-artifacts-d7aec9f2022ef2b4-dotnet-layer
37+
{
38+
"Role": {
39+
"Path": "/",
40+
"RoleName": "blank-csharp-role",
41+
"RoleId": "AROA6HOIFXAKKWARP5RSC",
42+
"Arn": "arn:aws:iam::978061735956:role/blank-csharp-role",
43+
"CreateDate": "2023-08-22T18:12:29+00:00",
44+
"AssumeRolePolicyDocument": {
45+
"Version": "2012-10-17",
46+
"Statement": [
47+
{
48+
"Effect": "Allow",
49+
"Action": [
50+
"sts:AssumeRole"
51+
],
52+
"Principal": {
53+
"Service": [
54+
"lambda.amazonaws.com"
55+
]
56+
}
57+
}
58+
]
59+
}
60+
}
61+
}
62+
63+
To build a Lambda layer that contains the function's runtime dependencies, run `2-build-layer.sh`. This also uploads the layer to an S3 bucket created by the first script.
64+
65+
blank-csharp$ ./2-build-layer.sh
66+
67+
# Deploy
68+
To deploy the application, run `3-deploy.sh`.
69+
70+
blank-csharp$ ./3-deploy.sh
71+
Amazon Lambda Tools for .NET Core applications (5.8.0)
72+
...
73+
Created publish archive ...
74+
Creating new Lambda function blank-csharp
75+
New Lambda function created
76+
77+
This script uses the .NET Amazon Lambda Tools to deploy the Lambda function. It uses the default settings from the `src/aws-lambda-tools-defaults.json` file.
78+
79+
To invoke the function, run `4-invoke.sh`.
80+
81+
blank-csharp$ ./4-invoke.sh
82+
{
83+
"StatusCode": 200,
84+
"ExecutedVersion": "$LATEST"
85+
}
86+
{"FunctionCount":13,"TotalCodeSize":598094248}
87+
88+
Let the script invoke the function a few times and then press `CRTL+C` to exit.
89+
90+
The application uses AWS X-Ray to trace requests. Open the [X-Ray console](https://console.aws.amazon.com/xray/home#/service-map) to view the service map. The following service map shows the function managing spot instances in Amazon EC2.
91+
92+
![Service Map](/sample-apps/blank-csharp-with-layer/images/blank-csharp-servicemap.png)
93+
94+
Choose a node in the main function graph. Then choose **View traces** to see a list of traces. Choose any trace to view a timeline that breaks down the work done by the function.
95+
96+
![Trace](/sample-apps/blank-csharp-with-layer/images/blank-csharp-trace.png)
97+
98+
# Cleanup
99+
To delete the application, run the cleanup script.
100+
101+
blank-csharp$ ./5-cleanup.sh
File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"Records": [
3+
{
4+
"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
5+
"receiptHandle": "MessageReceiptHandle",
6+
"body": "Hello from SQS!",
7+
"attributes": {
8+
"ApproximateReceiveCount": "1",
9+
"SentTimestamp": "1523232000000",
10+
"SenderId": "123456789012",
11+
"ApproximateFirstReceiveTimestamp": "1523232000001"
12+
},
13+
"messageAttributes": {},
14+
"md5OfBody": "7b270e59b47ff90a553787216d55d91d",
15+
"eventSource": "aws:sqs",
16+
"eventSourceARN": "arn:aws:sqs:us-west-2:123456789012:MyQueue",
17+
"awsRegion": "us-west-2"
18+
}
19+
]
20+
}
20.1 KB
Loading

0 commit comments

Comments
 (0)