|
1 |
| -# Blank function with layer (C#) |
2 |
| - |
3 |
| - |
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 |
| -# Setup |
19 |
| -Download or clone this repository. |
20 |
| - |
21 |
| - $ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git |
22 |
| - $ cd aws-lambda-developer-guide/sample-apps/blank-csharp |
23 |
| - |
24 |
| -To create a new bucket for deployment artifacts, run `1-create-bucket-and-role.sh`. |
25 |
| - |
26 |
| - blank-csharp$ ./1-create-bucket.sh |
27 |
| - make_bucket: lambda-artifacts-d7aec9f2022ef2b4 |
28 |
| - make_bucket: lambda-artifacts-d7aec9f2022ef2b4-dotnet-layer |
29 |
| - { |
30 |
| - "Role": { |
31 |
| - "Path": "/", |
32 |
| - "RoleName": "blank-csharp-role", |
33 |
| - "RoleId": "AROA6HOIFXAKKWARP5RSC", |
34 |
| - "Arn": "arn:aws:iam::978061735956:role/blank-csharp-role", |
35 |
| - "CreateDate": "2023-08-22T18:12:29+00:00", |
36 |
| - "AssumeRolePolicyDocument": { |
37 |
| - "Version": "2012-10-17", |
38 |
| - "Statement": [ |
39 |
| - { |
40 |
| - "Effect": "Allow", |
41 |
| - "Action": [ |
42 |
| - "sts:AssumeRole" |
43 |
| - ], |
44 |
| - "Principal": { |
45 |
| - "Service": [ |
46 |
| - "lambda.amazonaws.com" |
47 |
| - ] |
48 |
| - } |
49 |
| - } |
50 |
| - ] |
51 |
| - } |
52 |
| - } |
53 |
| - } |
54 |
| - |
55 |
| -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. |
56 |
| - |
57 |
| - blank-csharp$ ./2-build-layer.sh |
58 |
| - |
59 |
| -# Deploy |
60 |
| -To deploy the application, run `3-deploy.sh`. |
61 |
| - |
62 |
| - blank-csharp$ ./3-deploy.sh |
63 |
| - Amazon Lambda Tools for .NET Core applications (5.8.0) |
64 |
| - ... |
65 |
| - Created publish archive ... |
66 |
| - Creating new Lambda function blank-csharp |
67 |
| - New Lambda function created |
68 |
| - |
69 |
| -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. |
70 |
| - |
71 |
| -To invoke the function, run `4-invoke.sh`. |
72 |
| - |
73 |
| - blank-csharp$ ./4-invoke.sh |
74 |
| - { |
75 |
| - "StatusCode": 200, |
76 |
| - "ExecutedVersion": "$LATEST" |
77 |
| - } |
78 |
| - {"FunctionCount":13,"TotalCodeSize":598094248} |
79 |
| - |
80 |
| -Let the script invoke the function a few times and then press `CRTL+C` to exit. |
81 |
| - |
82 |
| -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. |
83 |
| - |
84 |
| - |
85 |
| - |
86 |
| -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. |
87 |
| - |
88 |
| - |
89 |
| - |
90 |
| -# Cleanup |
91 |
| -To delete the application, run the cleanup script. |
92 |
| - |
93 |
| - blank-csharp$ ./5-cleanup.sh |
| 1 | +# Blank function with layer (C#) |
| 2 | + |
| 3 | + |
| 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 8.0](https://dotnet.microsoft.com/download/dotnet-core/8.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 | +# Setup |
| 19 | +Download or clone this repository. |
| 20 | + |
| 21 | + $ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git |
| 22 | + $ cd aws-lambda-developer-guide/sample-apps/blank-csharp |
| 23 | + |
| 24 | +To create a new bucket for deployment artifacts, run `1-create-bucket-and-role.sh`. |
| 25 | + |
| 26 | + blank-csharp$ ./1-create-bucket.sh |
| 27 | + make_bucket: lambda-artifacts-d7aec9f2022ef2b4 |
| 28 | + make_bucket: lambda-artifacts-d7aec9f2022ef2b4-dotnet-layer |
| 29 | + { |
| 30 | + "Role": { |
| 31 | + "Path": "/", |
| 32 | + "RoleName": "blank-csharp-role", |
| 33 | + "RoleId": "AROA6HOIFXAKKWARP5RSC", |
| 34 | + "Arn": "arn:aws:iam::978061735956:role/blank-csharp-role", |
| 35 | + "CreateDate": "2023-08-22T18:12:29+00:00", |
| 36 | + "AssumeRolePolicyDocument": { |
| 37 | + "Version": "2012-10-17", |
| 38 | + "Statement": [ |
| 39 | + { |
| 40 | + "Effect": "Allow", |
| 41 | + "Action": [ |
| 42 | + "sts:AssumeRole" |
| 43 | + ], |
| 44 | + "Principal": { |
| 45 | + "Service": [ |
| 46 | + "lambda.amazonaws.com" |
| 47 | + ] |
| 48 | + } |
| 49 | + } |
| 50 | + ] |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | +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. |
| 56 | + |
| 57 | + blank-csharp$ ./2-build-layer.sh |
| 58 | + |
| 59 | +# Deploy |
| 60 | +To deploy the application, run `3-deploy.sh`. |
| 61 | + |
| 62 | + blank-csharp$ ./3-deploy.sh |
| 63 | + Amazon Lambda Tools for .NET Core applications (5.8.0) |
| 64 | + ... |
| 65 | + Created publish archive ... |
| 66 | + Creating new Lambda function blank-csharp |
| 67 | + New Lambda function created |
| 68 | + |
| 69 | +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. |
| 70 | + |
| 71 | +To invoke the function, run `4-invoke.sh`. |
| 72 | + |
| 73 | + blank-csharp$ ./4-invoke.sh |
| 74 | + { |
| 75 | + "StatusCode": 200, |
| 76 | + "ExecutedVersion": "$LATEST" |
| 77 | + } |
| 78 | + {"FunctionCount":13,"TotalCodeSize":598094248} |
| 79 | + |
| 80 | +Let the script invoke the function a few times and then press `CRTL+C` to exit. |
| 81 | + |
| 82 | +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. |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +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. |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +# Cleanup |
| 91 | +To delete the application, run the cleanup script. |
| 92 | + |
| 93 | + blank-csharp$ ./5-cleanup.sh |
0 commit comments