# Blank function (C#)
Original sample: https://github.com/awsdocs/aws-lambda-developer-guide/
![Architecture](/Telegram.Bot.Examples.AwsLambda.WebHook/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 3.1](https://dotnet.microsoft.com/download/dotnet-core/3.1)
- [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.
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`):
```
cli_binary_format=raw-in-base64-out
```
This setting enables the AWS CLI v2 to load JSON events from a file, matching the v1 behavior.
# 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](/Telegram.Bot.Examples.AwsLambda.WebHook/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](/Telegram.Bot.Examples.AwsLambda.WebHook/images/blank-csharp-trace.png)
# Cleanup
To delete the application, run the cleanup script.
blank-csharp$ ./4-cleanup.sh
# Telegram Bot WebHook AWS Lambda example
Replace `<token>` with your bot token in sources.
Use as above to deploy it as aws lambda.
If you have windows, you may run above scripts from docker:
`docker run --rm --entrypoint=sh -it -v ${PWD}:/work -w=/work -e AWS_ACCESS_KEY_ID=<your_access_key> -e AWS_SECRET_ACCESS_KEY=<your_secret_key> -e AWS_DEFAULT_REGION=us-west-2 amazon/aws-cli`
Comment out `dotnet lambda package` lines in `2-deploy.sh` and launch this command before deploy (cli image does not have .net).
In aws console create api gateway / rest / post / lambda function with lambda proxy integration enabled and link this function. Create stage for this method. Copy invoke url from stage/post. Post manually to `https://api.telegram.org/bot<token>/setWebhook` with `form-data: "url": "<your_invoke_url>"` to set webhook to lambda function.
Refer original webhook example for the rest of details.
没有合适的资源?快使用搜索试试~ 我知道了~
Examples for the Telegram.Bot C# Library.zip
共87个文件
cs:24个
json:15个
fs:8个
需积分: 5 0 下载量 105 浏览量
2024-01-05
14:53:50
上传
评论
收藏 410KB ZIP 举报
温馨提示
Examples for the Telegram.Bot C# Library
资源推荐
资源详情
资源评论
收起资源包目录
Examples for the Telegram.Bot C# Library.zip (87个子文件)
sss
.editorconfig 645B
Directory.Build.props 342B
Telegram.Bot.Examples.Polling
Services
UpdateHandler.cs 12KB
PollingService.cs 333B
ReceiverService.cs 411B
Abstract
IReceiverService.cs 208B
ReceiverServiceBase.cs 2KB
PollingServiceBase.cs 2KB
appsettings.Development.json 188B
Extensions.cs 394B
Files
tux.png 72KB
Telegram.Bot.Examples.Polling.csproj 634B
Program.cs 2KB
appsettings.json 188B
README.md 2KB
Telegram.Bot.Examples.InlineQueries
Properties
launchSettings.json 178B
Program.cs 3KB
Telegram.Bot.Examples.InlineQueries.csproj 437B
Articles
One.html 62B
Two.html 52B
Three.html 74B
README.md 861B
.github
dependabot.yml 818B
workflows
build_examples.yml 449B
.gitattributes 2KB
LICENSE 1KB
Telegram.Bot.Examples.WebHook
Filters
ValidateTelegramBotRequestAttribute.cs 2KB
Services
UpdateHandlers.cs 11KB
ConfigureWebhook.cs 2KB
appsettings.Development.json 330B
Extensions.cs 1KB
Files
tux.png 72KB
Telegram.Bot.Examples.WebHook.csproj 597B
Properties
launchSettings.json 480B
Program.cs 3KB
Controllers
BotController.cs 536B
appsettings.json 267B
README.md 2KB
Serverless
Telegram.Bot.Examples.AzureFunctions.IsolatedProcess.WebHook
.editorconfig 97B
host.json 217B
UpdateService.cs 873B
Telegram.Bot.Examples.AzureFunctions.IsolatedProcess.WebHook.csproj 1KB
Properties
launchSettings.json 201B
Program.cs 1KB
TelegramBot.cs 2KB
.gitignore 4KB
README.md 3KB
Telegram.Bot.Examples.AzureFunctions.WebHook
host.json 221B
UpdateService.cs 852B
TelegramBotFunction.cs 1KB
Telegram.Bot.Examples.AzureFunctions.WebHook.csproj 1008B
Startup.cs 1KB
README.md 2KB
Telegram.Bot.Examples.AwsLambda.WebHook
4-cleanup.sh 1KB
3-invoke.sh 342B
2-deploy.sh 478B
template.yml 638B
1-create-bucket.sh 202B
event.json 602B
images
sample-blank-csharp.png 49KB
blank-csharp-servicemap.png 20KB
blank-csharp-trace.png 68KB
lambda-bot.Tests
FunctionTest.cs 512B
lambda-bot.Tests.csproj 851B
README.md 4KB
lambda-bot
lambda-bot.csproj 986B
UpdateService.cs 1KB
aws-lambda-tools-defaults.json 711B
Properties
launchSettings.json 301B
Function.cs 1KB
Telegram.Bot.Examples.sln 14KB
.gitignore 3KB
FSharp.Examples.Polling
.editorconfig 645B
FSharp.Examples.Polling.fsproj 951B
Services
Internal
UpdateHandlerFuncs.fs 9KB
IReceiverService.fs 424B
PollingService.fs 2KB
ReceiverService.fs 2KB
UpdateHandler.fs 1KB
appsettings.Development.json 188B
Extensions.fs 609B
Files
tux.png 72KB
Properties
launchSettings.json 215B
Util.fs 532B
Program.fs 2KB
appsettings.json 188B
README.md 2KB
共 87 条
- 1
资源评论
Lei宝啊
- 粉丝: 1981
- 资源: 1330
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功