{"id":16507914,"url":"https://github.com/noahgift/dot-net-6-aws","last_synced_at":"2025-06-30T19:35:27.435Z","repository":{"id":141810134,"uuid":"460460643","full_name":"noahgift/dot-net-6-aws","owner":"noahgift","description":".NET 6 on AWS","archived":false,"fork":false,"pushed_at":"2022-05-27T20:29:18.000Z","size":273,"stargazers_count":6,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-02T02:46:53.960Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noahgift.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-17T14:04:30.000Z","updated_at":"2024-10-05T12:16:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"866a4c61-08e1-48be-bd3f-66055104123e","html_url":"https://github.com/noahgift/dot-net-6-aws","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/noahgift/dot-net-6-aws","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fdot-net-6-aws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fdot-net-6-aws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fdot-net-6-aws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fdot-net-6-aws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noahgift","download_url":"https://codeload.github.com/noahgift/dot-net-6-aws/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fdot-net-6-aws/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262839323,"owners_count":23372697,"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":[],"created_at":"2024-10-11T15:31:48.696Z","updated_at":"2025-06-30T19:35:27.404Z","avatar_url":"https://github.com/noahgift.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dot-net-6-aws-containers\n.NET 6 on AWS for Containers using Cloud9\n\n## This covers installation on Cloud9\n\n### Install .NET 6 from Microsoft\n\n```bash\nsudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm\nsudo yum install dotnet-sdk-6.0\nsudo yum install aspnetcore-runtime-6.0\nsudo yum install dotnet-runtime-6.0\n```\n\n### Create Hello World\n\n[setup.sh](https://github.com/noahgift/dot-net-6-aws/blob/main/setup.sh)\n```bash\ndotnet new console -o hello \\\n    \u0026\u0026 cd hello \\\n    \u0026\u0026 dotnet run\n```\n\n![5-4-2-cloud9-project-setup](https://user-images.githubusercontent.com/58792/154769693-c4d45cbf-0d6d-4f9a-b8bc-395a1c91208a.png)\n\n\n\n### Running Docker in Cloud9\n\nA good reference point is an AWS Lambda Dockerfile:\nhttps://gallery.ecr.aws/lambda/dotnet.  This contains instructions on how to build AWS Lambda that targets the .NET 6 runtime.\nAnother great resource is the official .NET 6 support on AWS:  https://github.com/aws-samples/aws-net-guides/tree/master/RuntimeSupport/dotnet6\n\nIn order to build containers, I first the Cloud9 environment needs resizing. Let's tackle that next.\n\n#### Resizing\n\nIt is a good idea to both resize your environment as well as cleanup a bit.\nYou can refer to Bash script by AWS that allows you to easily resize Cloud9:  https://docs.aws.amazon.com/cloud9/latest/user-guide/move-environment.html\n\nI have a copy of the script here:  https://github.com/noahgift/dot-net-6-aws/blob/main/utils/resize.sh.  To run it you do the following:\n\n```bash\nchmod +x resize.sh\n./resize.sh 50\n```\n\nAfter I run this on my system I see the following output.  Notice that the mount point `/dev/nvme0n1p1` now has `41G` free.\n\n```bash\nec2-user:~/environment/dot-net-6-aws (main) $ df -h\nFilesystem      Size  Used Avail Use% Mounted on\ndevtmpfs         32G     0   32G   0% /dev\ntmpfs            32G     0   32G   0% /dev/shm\ntmpfs            32G  536K   32G   1% /run\ntmpfs            32G     0   32G   0% /sys/fs/cgroup\n/dev/nvme0n1p1   50G  9.6G   41G  20% /\ntmpfs           6.3G     0  6.3G   0% /run/user/1000\ntmpfs           6.3G     0  6.3G   0% /run/user/0\n```\n\nNext let's build an AWS Lambda container with .NET 6.\n\n#### Containerized.NET 6 on Lambda \n\nTo build a Lambda container on my Cloud9 environment I cd into the Lambda directory:\n\n```bash\ncd /home/ec2-user/environment/dot-net-6-aws/Lambda\n```\nThen I run `docker build -t dotnet6-lambda:latest .`\n\n#### Containerized .NET 6 on API\n\nAnother way to go is to build a Microservice that deploys with a container service like AWS ECS or AWS App Runner.  Both methods offer an efficient way to deploy an API with minimal effort.\nTo get started first create a new web API project in Cloud9.\n\n```bash\ndotnet new web -n WebServiceAWS\n```\n\nRunning this in my Cloud9 environment generates the following output:\n\n```bash\nec2-user:~/environment/dot-net-6-aws (main) $ dotnet new web -n WebServiceAWS\nThe template \"ASP.NET Core Empty\" was created successfully.\n\nProcessing post-creation actions...\nRunning 'dotnet restore' on /home/ec2-user/environment/dot-net-6-aws/WebServiceAWS/WebServiceAWS.csproj...\n  Determining projects to restore...\n  Restored /home/ec2-user/environment/dot-net-6-aws/WebServiceAWS/WebServiceAWS.csproj (in 88 ms).\nRestore succeeded.\n```\n\nLet's change the default code a bit by adding slightly fancier route.  You can find more information about Routing in ASP.NET Core here:\nhttps://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-6.0. Note in the following example how similar this code looks to other high level languages like Node, Ruby, Python or Swift.\n\n```csharp\nvar builder = WebApplication.CreateBuilder(args);\nvar app = builder.Build();\n\napp.MapGet(\"/\", () =\u003e \"Home Page\");\napp.MapGet(\"/hello/{name:alpha}\", (string name) =\u003e $\"Hello {name}!\");\napp.Run();\n```\n\nNow you can run this code by changing into the directory using `dotnet run`\n\n```bash\ncd WebServiceAWS \u0026\u0026 dotnet run\n```\n\nThe output looks something like this in AWS Cloud9.  Note how cool it is that you can see the full content root path showing for your Cloud9 Environment making it easy to host multiple projects and switch back and forth between working on them.\n\n```bash\nec2-user:~/environment/dot-net-6-aws (main) $ cd WebServiceAWS \u0026\u0026 dotnet run\nBuilding...\ninfo: Microsoft.Hosting.Lifetime[14]\n      Now listening on: https://localhost:7117\ninfo: Microsoft.Hosting.Lifetime[14]\n      Now listening on: http://localhost:5262\ninfo: Microsoft.Hosting.Lifetime[0]\n      Application started. Press Ctrl+C to shut down.\n      Content root path: /home/ec2-user/environment/dot-net-6-aws/WebServiceAWS/\n```\n\nYou can see the output below, note how cool it is to toggle terminals side by side along side the code.\n\n![5-4-cloud9-aspnet](https://user-images.githubusercontent.com/58792/154587840-d892150d-9b11-4c42-aee3-7fb9400ce689.png)\n\n##### Containerize the Project\n\nNow let's convert our project to using a container so it can be deployed to services that support containers.\nTo do this create a `Dockerfile` in the project folder.\n\n```bash\nFROM mcr.microsoft.com/dotnet/sdk:6.0 AS build\nWORKDIR /src\nCOPY [\"WebServiceAWS.csproj\", \"./\"]\nRUN dotnet restore \"WebServiceAWS.csproj\"\nCOPY . .\nWORKDIR \"/src/.\"\nRUN dotnet build \"WebServiceAWS.csproj\" -c Release -o /app/build\n\nFROM build AS publish\nRUN dotnet publish \"WebServiceAWS.csproj\" -c Release -o /app/publish\n\nFROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base\nWORKDIR /app\nEXPOSE 8080\nENV ASPNETCORE_URLS=http://+:8080\n\nWORKDIR /app\nCOPY --from=publish /app/publish .\nENTRYPOINT [\"dotnet\", \"WebServiceAWS.dll\"]\n```\n\nNow build this container.\n\n`docker build . -t web-service-dotnet:latest`\n\nYou can take a look at the container by using `docker image ls`.\nThe output should look something like this.\n\n`web-service-dotnet  latest  3c191e7643d5   38 seconds ago   208MB`\n\nTo run it do the following:\n\n`docker run -p 8080:8080 web-service-dotnet:latest`\n\nThe output should like follows:\n\n```bash\n listening on: {address}\"}}\n{\"EventId\":0,\"LogLevel\":\"Information\",\"Category\":\"Microsoft.Hosting.Lifetime\",\"Message\":\"Application started. Press Ctrl\\u002BC to shut down.\",\"State\":{\"Message\":\"Application started. Press Ctrl\\u002BC to shut down.\",\"{OriginalFormat}\":\"Application started. Press Ctrl\\u002BC to shut down.\"}}\n{\"EventId\":0,\"LogLevel\":\"Information\",\"Category\":\"Microsoft.Hosting.Lifetime\",\"Message\":\"Hosting environment: Production\",\"State\":{\"Message\":\"Hosting environment: Production\",\"envName\":\"Production\",\"{OriginalFormat}\":\"Hosting environment: {envName}\"}}\n{\"EventId\":0,\"LogLevel\":\"Information\",\"Category\":\"Microsoft.Hosting.Lifetime\",\"Message\":\"Content root path: /app/\",\"State\":{\"Message\":\"Content root path: /app/\",\"contentRoot\":\"/app/\",\"{OriginalFormat}\":\"Content root path: {contentRoot}\"}}\n```\n\nNow invoke it via curl: `curl http://localhost:8080/hello/aws`\n\n![5-5-containerized-dotnet](https://user-images.githubusercontent.com/58792/154597821-85538b62-c1ba-486a-9250-9c43d3600be8.png)\n\n##### ECR\n\n![5-6-ecr](https://user-images.githubusercontent.com/58792/154720964-0e7de542-b640-4ce1-b78a-c0fd39a35aaf.png)\n\nCreate a new ECR Repo:\n\n![5-6-2-ecr-create](https://user-images.githubusercontent.com/58792/154752026-4ec362f8-c4d0-436f-9759-d9eb2ae928d8.png)\n\nNext click on the repo to find the push commands.\n\n![5-6-3-ecr-push](https://user-images.githubusercontent.com/58792/154752107-56b9bf03-d1c1-44b2-b906-091aa7f0841f.png)\n\nNow checkout the image:\n\n\n![5-6-4-ecr-image](https://user-images.githubusercontent.com/58792/154753326-fb3b0b4d-23fe-4e40-b447-e5aba40ef5b0.png)\n\n##### App Runner\n\n\u003cimg width=\"976\" alt=\"5-7-app-runner\" src=\"https://user-images.githubusercontent.com/58792/154722019-87efa041-ea03-40c4-a166-73122fc239a3.png\"\u003e\n\nSelect container:\n\n![5-7-2-app-runner-container](https://user-images.githubusercontent.com/58792/154760740-b62da26a-7ec0-4a11-9202-93d0866ed281.png)\n\nSelect Deploy process:\n\n![5-7-3-app-runner-deploy](https://user-images.githubusercontent.com/58792/154760762-38d0237c-6562-407b-93d4-599e603c0d03.png)\n\nSelect ports:\n\n![5-7-4-app-runner-ports](https://user-images.githubusercontent.com/58792/154760785-06dcf94c-55d2-445d-b83d-904ddfbd4be6.png)\n\nSelect service:\n\n![5-7-5-app-runner-service](https://user-images.githubusercontent.com/58792/154760825-7d49948f-16ec-4d26-a33c-493511c39afa.png)\n\nCurl API:\n\n![5-7-6-app-runner-curl](https://user-images.githubusercontent.com/58792/154760885-45a7dc18-6658-4e27-b5bb-f1a3a8d6b3fb.png)\n\nReview Architecture:\n\n![5-7-7-app-runner-architecture](https://user-images.githubusercontent.com/58792/154760904-887b8c28-1787-4e21-b015-8495ba0d3ee1.png)\n\n\n\n##### AWS Copilot CLI\n\n\n\u003cimg width=\"1218\" alt=\"5-8-co-pilot\" src=\"https://user-images.githubusercontent.com/58792/154723375-76907b87-9af2-4b25-8ac6-9fc63ea20ffb.png\"\u003e\n\n## Reference\n\n* [Watch walkthrough on YouTube](https://www.youtube.com/watch?v=nUAQHzz_t9k)\n* [Watch walkthrough on O'Reilly](https://learning.oreilly.com/search/?query=noah%20gift\u0026extended_publisher_data=true\u0026highlight=true\u0026include_assessments=false\u0026include_case_studies=true\u0026include_courses=true\u0026include_playlists=true\u0026include_collections=true\u0026include_notebooks=true\u0026include_sandboxes=true\u0026include_scenarios=true\u0026is_academic_institution_account=false\u0026source=user\u0026sort=relevance\u0026facet_json=true\u0026json_facets=true\u0026page=0\u0026include_facets=true\u0026include_practice_exams=true)\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoahgift%2Fdot-net-6-aws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoahgift%2Fdot-net-6-aws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoahgift%2Fdot-net-6-aws/lists"}