{"id":16485195,"url":"https://github.com/antoniofalcaojr/dotnet.awslambda.autoscaling","last_synced_at":"2025-03-23T12:32:54.019Z","repository":{"id":36960582,"uuid":"280539309","full_name":"AntonioFalcaoJr/Dotnet.AWSLambda.AutoScaling","owner":"AntonioFalcaoJr","description":"This project demonstrates the integration with AWS Auto Scaling service and .NET Core, using SAM for building and test.","archived":false,"fork":false,"pushed_at":"2023-03-06T08:57:37.000Z","size":229,"stargazers_count":10,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-12T13:24:22.423Z","etag":null,"topics":["autoscaling","aws","aws-autoscaling","aws-cli","aws-lambda","dotnet","dotnet-cli","dotnet-core"],"latest_commit_sha":null,"homepage":"https://dev.to/antoniofalcao/using-net-core-in-aws-lambda-with-sam-and-building-an-auto-scaling-manager-3gjc","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AntonioFalcaoJr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-17T22:49:50.000Z","updated_at":"2023-08-24T07:18:41.000Z","dependencies_parsed_at":"2023-01-17T08:28:34.145Z","dependency_job_id":null,"html_url":"https://github.com/AntonioFalcaoJr/Dotnet.AWSLambda.AutoScaling","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonioFalcaoJr%2FDotnet.AWSLambda.AutoScaling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonioFalcaoJr%2FDotnet.AWSLambda.AutoScaling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonioFalcaoJr%2FDotnet.AWSLambda.AutoScaling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AntonioFalcaoJr%2FDotnet.AWSLambda.AutoScaling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AntonioFalcaoJr","download_url":"https://codeload.github.com/AntonioFalcaoJr/Dotnet.AWSLambda.AutoScaling/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221850628,"owners_count":16891659,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autoscaling","aws","aws-autoscaling","aws-cli","aws-lambda","dotnet","dotnet-cli","dotnet-core"],"created_at":"2024-10-11T13:24:33.622Z","updated_at":"2024-10-28T15:48:01.603Z","avatar_url":"https://github.com/AntonioFalcaoJr.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# .NET Core 3.x AWS Lambda with SAM \u003cbr\u003e Auto Scaling Manager\n\nThis project demonstrates the integration with **AWS Auto-Scaling** service and **.NET Core**, using **SAM** for building and test.\n\nThis sample contains source code and supporting files for a **serverless application** that you can deploy with the **SAM CLI**. \n\n- [`./src`](./src) - Multilayer .NET Core project for the application's Lambda function.\n- [`./.events`](./.events) - Invocation events that you can use to invoke the function.\n- [`./test`](./test) - Unit tests for the application code with XUnit. \n- [`template.yaml`](./template.yaml) - A template that defines the application's AWS resources.\n\n## How its works\n\nUsing a JSON as input is possible to **suspend** or **resume** processes from a specific auto-scaling by _tag name_.\n\n\u003e **Use case:** SUSPEND the _Terminate_ and _Launch_ processes as the initial stage from **Blue-Green Deploy** on **Code Pipeline** and then, RESUME in the final stage.\n\nJSON sample for use at AWS or in this project.\n\n```json5\n{\n    \"Scalings\": [\n        {\n            \"Tag\": \"tag-name-here\",\n            \"Suspend\": false\n        }\n    ]\n}\n```\n\nMany scalings:\n\n```json5\n{\n    \"Scalings\": [\n        {\n            \"Tag\": \"tag-name-here\",\n            \"Suspend\": false\n        },\n        {\n            \"Tag\": \"tag-name-here\",\n            \"Suspend\": true\n        }\n    ]\n}\n```\n\nAbout **Processes**, is possible to specify, but if not it will use the default list.\n\n```json5\n{\n    \"Scalings\": [\n        {\n            \"Tag\": \"tag-name-here\",\n            \"Suspend\": false,\n            \"Processes\": [\n                \"Terminate\",\n                \"Launch\"\n            ]\n        }\n    ]\n}\n```\n\nDefault values are defined on file [`ProcessService.cs`](./src/Dotnet.AWSLambda.AutoScaling.Services/Processes/ProcessService.cs):\n\n```c#\npublic class ProcessService : IProcessService\n{\n    private static ProcessType LaunchProcessType =\u003e new ProcessType {ProcessName = \"Launch\"};\n    private static ProcessType ScheduledActionsProcessType =\u003e new ProcessType {ProcessName = \"ScheduledActions\"};\n    private static ProcessType TerminateProcessType =\u003e new ProcessType {ProcessName = \"Terminate\"};\n\n// comment for brevity\n}\n```\n\n## Function Project\n\nThis project consists of:\n* [`Dotnet.AWSLambda.AutoScaling.Application.Function.cs`](./src/Dotnet.AWSLambda.AutoScaling.Application/Function.cs) - class file containing a class with a single function handler method;\n* [`aws-lambda-tools-defaults.json`](./aws-lambda-tools-defaults.json) - default argument settings for use with **Rider** or **Visual Studio** and command line deployment tools for AWS.\n\n## Amazon.Lambda.Tools:\n\nInstall Amazon.Lambda.Tools Global Tools if not already installed.\n\n```bash\ndotnet tool install -g Amazon.Lambda.Tools\n```\n\nIf already installed check if a new version is available.\n\n```bash\ndotnet tool update -g Amazon.Lambda.Tools\n```\n\n## About SAM\n\nThe **Serverless Application Model Command Line Interface** (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses **Docker** to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API.\n\nTo use the SAM CLI, you need the following tools.\n\n* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)\n* .NET Core - [Install .NET Core](https://www.microsoft.com/net/download)\n* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition\u0026offering=community)\n\n## Use the SAM CLI to build and test locally\n\nBuild application with the `sam build` command.\n\n```bash\nsam build\n```\n\nThe SAM CLI installs dependencies defined in `./src/Dotnet.AWSLambda.AutoScaling.Application/Dotnet.AWSLambda.AutoScaling.Application.csproj`, creates a deployment package, and saves it in the `.aws-sam/build` folder.\n\n#### Events\n\nTest a single function by invoking it directly with a test **event**. An event is a JSON document that represents the input that the function receives from the event source. Test events are included in the [`./.events`](./.events) folder in this project.\n\n\u003e [`json-event.json`](./.events/json-event.json) represents a simple json input.    \n\u003e [`request-event.json`](./.events/request-event.json) represents a request json input.\n\nRun functions locally and invoke them with the `sam local invoke` command.\n\n```bash\nsam local invoke -e json-event.json\n```\nOR\n\n```bash\nsam local invoke -e request-event.json\n```\n\n#### API Request\n\nThe **SAM CLI** can also emulate the application's as API. Use the `sam local start-api` to run the API locally on port 3000.\n\n```bash\nsam local start-api\n```\n\nThen, is possible to request using **cURL** or **REST Client**:\n\n\u003e cURL\n\n```bash\ncurl --header \"Content-Type: application/json\" -X POST -d \"{ 'Scalings': [ { 'Tag': 'your-tag-name-here', 'Suspend': false }, { 'Tag': 'your-tag-name-h', 'Suspend': true } ] }\" http://127.0.0.1:3000/api\n```\n\u003e REST Client\n\n```http request\nPOST http://127.0.0.1:3000/api/\ncontent-type: application/json\n\n{\n    \"Scalings\": [\n        {\n            \"Tag\": \"tag-name-here\",\n            \"Suspend\": false\n        },\n        {\n            \"Tag\": \"tag-name-here\",\n            \"Suspend\": true\n        }\n    ]\n}\n```\n\n#### API settings\n\nThe **SAM CLI** reads the application template to determine the API's routes and the functions that they invoke.\n\n```yaml\n  Events:\n    AutoScalingManager:\n      Type: Api\n      Properties:\n        Path: '/api'\n        Method: post\n```\n\n## Credentials \n\nYou can set credentials in the AWS credentials file on your local system. This file must be located in one of the following locations:\n\n* `~/.aws/credentials` on Linux or macOS\n\n* `C:\\Users\\USERNAME\\.aws\\credentials` on Windows\n\nThis file should contain lines in the following format:\n\n```bash\n[default]\naws_access_key_id = your_access_key_id\naws_secret_access_key = your_secret_access_key\n```\n\n* Environment variables – You can set the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables.\n\nTo set these variables on Linux or macOS, use the export command: \n\n```bash\nexport AWS_ACCESS_KEY_ID=your_access_key_id\nexport AWS_SECRET_ACCESS_KEY=your_secret_access_key\n```\n\nTo set these variables on Windows, use the set command: \n\n```bash\nset AWS_ACCESS_KEY_ID=your_access_key_id\nset AWS_SECRET_ACCESS_KEY=your_secret_access_key\n```\n\nIf you are testing this lambda project with **SAM**, is necessary to inform the credentials on [`template.yaml`](./template.yaml):\n\n```yaml\n  Environment:\n    Variables:\n      AWS_ACCESS_KEY_ID: VALUE\n      AWS_SECRET_ACCESS_KEY: VALUE\n      AWS_DEFAULT_REGION: VALUE\n```\n\n### Unit tests\n\nTests are defined in the `test` folder in this project.\n\n```bash\ndotnet test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantoniofalcaojr%2Fdotnet.awslambda.autoscaling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantoniofalcaojr%2Fdotnet.awslambda.autoscaling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantoniofalcaojr%2Fdotnet.awslambda.autoscaling/lists"}