Thanks to visit codestin.com
Credit goes to github.com

Skip to content

.NET app updates for blank-csharp, blank-csharp-with-layer #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.DS_Store
186 changes: 93 additions & 93 deletions sample-apps/blank-csharp-with-layer/README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
# Blank function with layer (C#)

![Architecture](/sample-apps/blank-csharp/images/sample-blank-csharp.png)

The project source includes function code and supporting resources:

- `src/blank-csharp` - A C# .NET Core function.
- `1-create-bucket.sh`, `2-deploy.sh`, etc. - Shell scripts that use the AWS CLI to deploy and manage the application.

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.

# Requirements
- [.NET Core SDK 6.0](https://dotnet.microsoft.com/download/dotnet-core/6.0)
- [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.
- 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.
- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer.

# Setup
Download or clone this repository.

$ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git
$ cd aws-lambda-developer-guide/sample-apps/blank-csharp

To create a new bucket for deployment artifacts, run `1-create-bucket-and-role.sh`.

blank-csharp$ ./1-create-bucket.sh
make_bucket: lambda-artifacts-d7aec9f2022ef2b4
make_bucket: lambda-artifacts-d7aec9f2022ef2b4-dotnet-layer
{
"Role": {
"Path": "/",
"RoleName": "blank-csharp-role",
"RoleId": "AROA6HOIFXAKKWARP5RSC",
"Arn": "arn:aws:iam::978061735956:role/blank-csharp-role",
"CreateDate": "2023-08-22T18:12:29+00:00",
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sts:AssumeRole"
],
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
]
}
}
}

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.

blank-csharp$ ./2-build-layer.sh

# Deploy
To deploy the application, run `3-deploy.sh`.

blank-csharp$ ./3-deploy.sh
Amazon Lambda Tools for .NET Core applications (5.8.0)
...
Created publish archive ...
Creating new Lambda function blank-csharp
New Lambda function created

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.

To invoke the function, run `4-invoke.sh`.

blank-csharp$ ./4-invoke.sh
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
{"FunctionCount":13,"TotalCodeSize":598094248}

Let the script invoke the function a few times and then press `CRTL+C` to exit.

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.

![Service Map](/sample-apps/blank-csharp-with-layer/images/blank-csharp-servicemap.png)

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.

![Trace](/sample-apps/blank-csharp-with-layer/images/blank-csharp-trace.png)

# Cleanup
To delete the application, run the cleanup script.

blank-csharp$ ./5-cleanup.sh
# Blank function with layer (C#)
![Architecture](/sample-apps/blank-csharp/images/sample-blank-csharp.png)
The project source includes function code and supporting resources:
- `src/blank-csharp` - A C# .NET Core function.
- `1-create-bucket.sh`, `2-deploy.sh`, etc. - Shell scripts that use the AWS CLI to deploy and manage the application.
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.
# Requirements
- [.NET Core SDK 8.0](https://dotnet.microsoft.com/download/dotnet-core/8.0)
- [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.
- 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.
- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer.
# Setup
Download or clone this repository.
$ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git
$ cd aws-lambda-developer-guide/sample-apps/blank-csharp
To create a new bucket for deployment artifacts, run `1-create-bucket-and-role.sh`.
blank-csharp$ ./1-create-bucket.sh
make_bucket: lambda-artifacts-d7aec9f2022ef2b4
make_bucket: lambda-artifacts-d7aec9f2022ef2b4-dotnet-layer
{
"Role": {
"Path": "/",
"RoleName": "blank-csharp-role",
"RoleId": "AROA6HOIFXAKKWARP5RSC",
"Arn": "arn:aws:iam::978061735956:role/blank-csharp-role",
"CreateDate": "2023-08-22T18:12:29+00:00",
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sts:AssumeRole"
],
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}
]
}
}
}
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.
blank-csharp$ ./2-build-layer.sh
# Deploy
To deploy the application, run `3-deploy.sh`.
blank-csharp$ ./3-deploy.sh
Amazon Lambda Tools for .NET Core applications (5.8.0)
...
Created publish archive ...
Creating new Lambda function blank-csharp
New Lambda function created
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.
To invoke the function, run `4-invoke.sh`.
blank-csharp$ ./4-invoke.sh
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
{"FunctionCount":13,"TotalCodeSize":598094248}
Let the script invoke the function a few times and then press `CRTL+C` to exit.
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.
![Service Map](/sample-apps/blank-csharp-with-layer/images/blank-csharp-servicemap.png)
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.
![Trace](/sample-apps/blank-csharp-with-layer/images/blank-csharp-trace.png)
# Cleanup
To delete the application, run the cleanup script.
blank-csharp$ ./5-cleanup.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"Information" : [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",

"dotnet lambda help",

"All the command line options for the Lambda command can be specified in this file."
],

"profile":"default",
"region" : "us-east-1",
"configuration" : "Release",
"framework" : "net6.0",
"function-runtime":"dotnet6",
"function-memory-size" : 512,
"function-timeout" : 30,
"function-handler" : "blank-csharp::blankCsharp.Function::FunctionHandler",
"function-role" : "blank-csharp-role"
}
{
"Information" : [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile":"default",
"region" : "us-east-1",
"configuration" : "Release",
"framework" : "net8.0",
"function-runtime":"dotnet8",
"function-memory-size" : 512,
"function-timeout" : 30,
"function-handler" : "blank-csharp::blankCsharp.Function::FunctionHandler",
"function-role" : "blank-csharp-role"
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="2.1.0" />
<PackageReference Include="AWSSDK.Core" Version="3.7.103.24" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.104.3" />
<PackageReference Include="AWSXRayRecorder.Core" Version="2.13.0" />
<PackageReference Include="AWSXRayRecorder.Handlers.AwsSdk" Version="2.11.0" />
</ItemGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="2.1.0" />
<PackageReference Include="AWSSDK.Core" Version="3.7.103.24" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.104.3" />
<PackageReference Include="AWSXRayRecorder.Core" Version="2.13.0" />
<PackageReference Include="AWSXRayRecorder.Handlers.AwsSdk" Version="2.11.0" />
</ItemGroup>
</Project>
132 changes: 66 additions & 66 deletions sample-apps/blank-csharp/README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
# Blank function (C#)

![Architecture](/sample-apps/blank-csharp/images/sample-blank-csharp.png)

The project source includes function code and supporting resources:

- `src/blank-csharp` - A C# .NET Core function.
- `template.yml` - An AWS CloudFormation template that creates an application.
- `1-create-bucket.sh`, `2-deploy.sh`, etc. - Shell scripts that use the AWS CLI to deploy and manage the application.

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.

# Requirements
- [.NET Core SDK 6.0](https://dotnet.microsoft.com/download/dotnet-core/6.0)
- [AWS extensions for .NET CLI](https://github.com/aws/aws-extensions-for-dotnet-cli)
- 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.
- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer.

# Setup
Download or clone this repository.

$ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git
$ cd aws-lambda-developer-guide/sample-apps/blank-csharp

To create a new bucket for deployment artifacts, run `1-create-bucket.sh`.

blank-csharp$ ./1-create-bucket.sh
make_bucket: lambda-artifacts-a5e491dbb5b22e0d

# Deploy
To deploy the application, run `2-deploy.sh`.

blank-csharp$ ./2-deploy.sh
Amazon Lambda Tools for .NET Core applications (4.0.0)
Executing publish command
Uploading to e678bc216e6a0d510d661ca9ae2fd941 1009985 / 1009985.0 (100.00%)
Successfully packaged artifacts and wrote output template to file out.yml.
Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - blank-csharp

This script uses AWS CloudFormation to deploy the Lambda functions and an IAM role. If the AWS CloudFormation stack that contains the resources already exists, the script updates it with any changes to the template or function code.

To invoke the function, run `3-invoke.sh`.

blank-csharp$ ./3-invoke.sh
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
{"FunctionCount":43,"TotalCodeSize":362867335}

Let the script invoke the function a few times and then press `CRTL+C` to exit.

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.

![Service Map](/sample-apps/blank-csharp/images/blank-csharp-servicemap.png)

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.

![Trace](/sample-apps/blank-csharp/images/blank-csharp-trace.png)

# Cleanup
To delete the application, run the cleanup script.

blank-csharp$ ./4-cleanup.sh
# Blank function (C#)
![Architecture](/sample-apps/blank-csharp/images/sample-blank-csharp.png)
The project source includes function code and supporting resources:
- `src/blank-csharp` - A C# .NET Core function.
- `template.yml` - An AWS CloudFormation template that creates an application.
- `1-create-bucket.sh`, `2-deploy.sh`, etc. - Shell scripts that use the AWS CLI to deploy and manage the application.
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.
# Requirements
- [.NET Core SDK 8.0](https://dotnet.microsoft.com/download/dotnet-core/8.0)
- [AWS extensions for .NET CLI](https://github.com/aws/aws-extensions-for-dotnet-cli)
- 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.
- [The AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) v1.17 or newer.
# Setup
Download or clone this repository.
$ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git
$ cd aws-lambda-developer-guide/sample-apps/blank-csharp
To create a new bucket for deployment artifacts, run `1-create-bucket.sh`.
blank-csharp$ ./1-create-bucket.sh
make_bucket: lambda-artifacts-a5e491dbb5b22e0d
# Deploy
To deploy the application, run `2-deploy.sh`.
blank-csharp$ ./2-deploy.sh
Amazon Lambda Tools for .NET Core applications (4.0.0)
Executing publish command
Uploading to e678bc216e6a0d510d661ca9ae2fd941 1009985 / 1009985.0 (100.00%)
Successfully packaged artifacts and wrote output template to file out.yml.
Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - blank-csharp
This script uses AWS CloudFormation to deploy the Lambda functions and an IAM role. If the AWS CloudFormation stack that contains the resources already exists, the script updates it with any changes to the template or function code.
To invoke the function, run `3-invoke.sh`.
blank-csharp$ ./3-invoke.sh
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
{"FunctionCount":43,"TotalCodeSize":362867335}
Let the script invoke the function a few times and then press `CRTL+C` to exit.
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.
![Service Map](/sample-apps/blank-csharp/images/blank-csharp-servicemap.png)
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.
![Trace](/sample-apps/blank-csharp/images/blank-csharp-trace.png)
# Cleanup
To delete the application, run the cleanup script.
blank-csharp$ ./4-cleanup.sh
Loading