├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .vscode ├── extensions.json ├── launch.json └── tasks.json ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── DemoSolution.sln ├── LICENSE ├── README.md ├── Ste-by-step-guide.md ├── apps └── src │ ├── FunctionOne │ ├── Controllers │ │ └── CalculatorController.cs │ ├── FunctionOne.csproj │ ├── Program.cs │ ├── Readme.md │ ├── appsettings.Development.json │ ├── appsettings.json │ └── aws-lambda-tools-defaults.json │ ├── FunctionThree │ ├── Controllers │ │ └── CalculatorController.cs │ ├── FunctionThree.csproj │ ├── Program.cs │ ├── Readme.md │ ├── appsettings.Development.json │ ├── appsettings.json │ └── aws-lambda-tools-defaults.json │ └── FunctionTwo │ ├── Controllers │ └── CalculatorController.cs │ ├── FunctionTwo.csproj │ ├── Program.cs │ ├── Readme.md │ ├── appsettings.Development.json │ ├── appsettings.json │ └── aws-lambda-tools-defaults.json └── infra ├── .gitignore ├── README.md ├── cdk.json └── src ├── Infra.sln └── Infra ├── GlobalSuppressions.cs ├── Infra.csproj ├── InfraStack.cs └── Program.cs /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # This is a comment. 2 | # Each line is a file pattern followed by one or more owners. 3 | 4 | # These owners will be the default owners for everything in 5 | # the repo. Unless a later match takes precedence, 6 | # @global-owner1 and @global-owner2 will be requested for 7 | # review when someone opens a pull request. 8 | * @ulili5 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ##### SUMMARY 2 | 3 | 4 | ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF 5 | 6 | 7 | ### TEST PLAN 8 | 9 | 10 | ### ADDITIONAL INFORMATION 11 | 12 | 13 | - [ ] Has associated issue: 14 | - [ ] Changes UI 15 | - [ ] Introduces new feature or API 16 | - [ ] Removes existing feature or API 17 | - [ ] Fixes bug 18 | - [ ] Refactors code 19 | - [ ] Adds test(s) 20 | - [ ] Vulnerability 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | bin/ 23 | Bin/ 24 | obj/ 25 | Obj/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | /wwwroot/dist/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | # NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | *_i.c 45 | *_p.c 46 | *_i.h 47 | *.ilk 48 | *.meta 49 | *.obj 50 | *.pch 51 | *.pdb 52 | *.pgc 53 | *.pgd 54 | *.rsp 55 | *.sbr 56 | *.tlb 57 | *.tli 58 | *.tlh 59 | *.tmp 60 | *.tmp_proj 61 | *.log 62 | *.vspscc 63 | *.vssscc 64 | .builds 65 | *.pidb 66 | *.svclog 67 | *.scc 68 | 69 | # Chutzpah Test files 70 | _Chutzpah* 71 | 72 | # Visual C++ cache files 73 | ipch/ 74 | *.aps 75 | *.ncb 76 | *.opendb 77 | *.opensdf 78 | *.sdf 79 | *.cachefile 80 | 81 | # Visual Studio profiler 82 | *.psess 83 | *.vsp 84 | *.vspx 85 | *.sap 86 | 87 | # TFS 2012 Local Workspace 88 | $tf/ 89 | 90 | # Guidance Automation Toolkit 91 | *.gpState 92 | 93 | # ReSharper is a .NET coding add-in 94 | _ReSharper*/ 95 | *.[Rr]e[Ss]harper 96 | *.DotSettings.user 97 | 98 | # JustCode is a .NET coding add-in 99 | .JustCode 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | _NCrunch_* 109 | .*crunch*.local.xml 110 | nCrunchTemp_* 111 | 112 | # MightyMoose 113 | *.mm.* 114 | AutoTest.Net/ 115 | 116 | # Web workbench (sass) 117 | .sass-cache/ 118 | 119 | # Installshield output folder 120 | [Ee]xpress/ 121 | 122 | # DocProject is a documentation generator add-in 123 | DocProject/buildhelp/ 124 | DocProject/Help/*.HxT 125 | DocProject/Help/*.HxC 126 | DocProject/Help/*.hhc 127 | DocProject/Help/*.hhk 128 | DocProject/Help/*.hhp 129 | DocProject/Help/Html2 130 | DocProject/Help/html 131 | 132 | # Click-Once directory 133 | publish/ 134 | 135 | # Publish Web Output 136 | *.[Pp]ublish.xml 137 | *.azurePubxml 138 | # TODO: Comment the next line if you want to checkin your web deploy settings 139 | # but database connection strings (with potential passwords) will be unencrypted 140 | *.pubxml 141 | *.publishproj 142 | 143 | # NuGet Packages 144 | *.nupkg 145 | # The packages folder can be ignored because of Package Restore 146 | **/packages/* 147 | # except build/, which is used as an MSBuild target. 148 | !**/packages/build/ 149 | # Uncomment if necessary however generally it will be regenerated when needed 150 | #!**/packages/repositories.config 151 | 152 | # Microsoft Azure Build Output 153 | csx/ 154 | *.build.csdef 155 | 156 | # Microsoft Azure Emulator 157 | ecf/ 158 | rcf/ 159 | 160 | # Microsoft Azure ApplicationInsights config file 161 | ApplicationInsights.config 162 | 163 | # Windows Store app package directory 164 | AppPackages/ 165 | BundleArtifacts/ 166 | 167 | # Visual Studio cache files 168 | # files ending in .cache can be ignored 169 | *.[Cc]ache 170 | # but keep track of directories ending in .cache 171 | !*.[Cc]ache/ 172 | 173 | # Others 174 | ClientBin/ 175 | ~$* 176 | *~ 177 | *.dbmdl 178 | *.dbproj.schemaview 179 | *.pfx 180 | *.publishsettings 181 | orleans.codegen.cs 182 | 183 | /node_modules 184 | 185 | # RIA/Silverlight projects 186 | Generated_Code/ 187 | 188 | # Backup & report files from converting an old project file 189 | # to a newer Visual Studio version. Backup files are not needed, 190 | # because we have git ;-) 191 | _UpgradeReport_Files/ 192 | Backup*/ 193 | UpgradeLog*.XML 194 | UpgradeLog*.htm 195 | 196 | # SQL Server files 197 | *.mdf 198 | *.ldf 199 | 200 | # Business Intelligence projects 201 | *.rdl.data 202 | *.bim.layout 203 | *.bim_*.settings 204 | 205 | # Microsoft Fakes 206 | FakesAssemblies/ 207 | 208 | # GhostDoc plugin setting file 209 | *.GhostDoc.xml 210 | 211 | # Node.js Tools for Visual Studio 212 | .ntvs_analysis.dat 213 | 214 | # Visual Studio 6 build log 215 | *.plg 216 | 217 | # Visual Studio 6 workspace options file 218 | *.opt 219 | 220 | # Visual Studio LightSwitch build output 221 | **/*.HTMLClient/GeneratedArtifacts 222 | **/*.DesktopClient/GeneratedArtifacts 223 | **/*.DesktopClient/ModelManifest.xml 224 | **/*.Server/GeneratedArtifacts 225 | **/*.Server/ModelManifest.xml 226 | _Pvt_Extensions 227 | 228 | # Paket dependency manager 229 | .paket/paket.exe 230 | 231 | # FAKE - F# Make 232 | .fake/ 233 | .DS_Store 234 | # Avoid commit AWS Cred 235 | **/*.env 236 | 237 | # See https://help.github.com/ignore-files/ for more about ignoring files. 238 | 239 | # dependencies 240 | **/node_modules 241 | 242 | # testing 243 | /coverage 244 | 245 | # production 246 | /build 247 | 248 | # misc 249 | .DS_Store 250 | .env.local 251 | .env.development.local 252 | .env.test.local 253 | .env.production.local 254 | 255 | npm-debug.log* 256 | yarn-debug.log* 257 | yarn-error.log* 258 | 259 | 260 | # Un-ignore the CDK bin directory. 261 | !**/cdk/bin 262 | src/ModernTacoShop.TrackOrder.Server/aws-logger-errors.txt 263 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "fernandoescolar.vscode-solution-explorer", 4 | "ms-dotnettools.csharp", 5 | "jorgeserrano.vscode-csharp-snippets", 6 | "k--kato.docomment", 7 | "fudge.auto-using", 8 | "tdallau-csharpextensions.csharpextensions" 9 | ] 10 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [{ 4 | // Use IntelliSense to find out which attributes exist for C# debugging 5 | // Use hover for the description of the existing attributes 6 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 7 | "name": "FunctionOne:.NET Core Launch (web)", 8 | "type": "coreclr", 9 | "request": "launch", 10 | "preLaunchTask": "build:FunctionOne", 11 | // If you have changed target frameworks, make sure to update the program path. 12 | "program": "${workspaceFolder}/apps/src/FunctionOne/bin/Debug/net6.0/FunctionOne.dll", 13 | "args": [], 14 | "cwd": "${workspaceFolder}/apps/src/FunctionOne", 15 | "stopAtEntry": false, 16 | // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser 17 | "serverReadyAction": { 18 | "action": "openExternally", 19 | "pattern": "\\bNow listening on:\\s+(https?://\\S+)" 20 | }, 21 | "env": { 22 | "ASPNETCORE_ENVIRONMENT": "Development", 23 | "ASPNETCORE_URLS": "http://localhost:5051" 24 | }, 25 | "sourceFileMap": { 26 | "/Views": "${workspaceFolder}/apps/src/FunctionOne/Views" 27 | } 28 | }, 29 | { 30 | "name": "FunctionTwo: .NET Core Launch (web)", 31 | "type": "coreclr", 32 | "request": "launch", 33 | "preLaunchTask": "build:FunctionTwo", 34 | "program": "${workspaceFolder}/apps/src/FunctionTwo/bin/Debug/net6.0/FunctionTwo.dll", 35 | "args": [], 36 | "cwd": "${workspaceFolder}/apps/src/FunctionTwo", 37 | "stopAtEntry": false, 38 | "serverReadyAction": { 39 | "action": "openExternally", 40 | "pattern": "\\bNow listening on:\\s+(https?://\\S+)" 41 | }, 42 | "env": { 43 | "ASPNETCORE_ENVIRONMENT": "Development", 44 | "ASPNETCORE_URLS": "http://localhost:5052" 45 | }, 46 | "sourceFileMap": { 47 | "/Views": "${workspaceFolder}/apps/src/FunctionTwo/Views" 48 | } 49 | }, 50 | { 51 | "name": "FunctionThree: .NET Core Launch (web)", 52 | "type": "coreclr", 53 | "request": "launch", 54 | "preLaunchTask": "build:FunctionThree", 55 | "program": "${workspaceFolder}/apps/src/FunctionThree/bin/Debug/net6.0/FunctionThree.dll", 56 | "args": [], 57 | "cwd": "${workspaceFolder}/apps/src/FunctionThree", 58 | "stopAtEntry": false, 59 | "serverReadyAction": { 60 | "action": "openExternally", 61 | "pattern": "\\bNow listening on:\\s+(https?://\\S+)" 62 | }, 63 | "env": { 64 | "ASPNETCORE_ENVIRONMENT": "Development", 65 | "ASPNETCORE_URLS": "http://localhost:5053" 66 | }, 67 | "sourceFileMap": { 68 | "/Views": "${workspaceFolder}/apps/src/FunctionThree/Views" 69 | } 70 | }, 71 | ] 72 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [{ 4 | "label": "clean:FunctionTwo", 5 | "command": "rm", 6 | "type": "shell", 7 | "args": [ 8 | "-rf", 9 | "${workspaceFolder}/apps/src/FunctionTwo/bin", 10 | "${workspaceFolder}/apps/src/FunctionTwo/obj", 11 | ], 12 | }, 13 | { 14 | "label": "build:FunctionTwo", 15 | "command": "dotnet", 16 | "type": "process", 17 | "args": [ 18 | "build", 19 | "${workspaceFolder}/apps/src/FunctionTwo/FunctionTwo.csproj", 20 | "/property:GenerateFullPaths=true", 21 | "/consoleloggerparameters:NoSummary" 22 | ], 23 | "problemMatcher": "$msCompile" 24 | }, 25 | { 26 | "label": "publish:FunctionTwo", 27 | "command": "dotnet", 28 | "type": "process", 29 | "args": [ 30 | "publish", 31 | "${workspaceFolder}/apps/src/FunctionTwo/FunctionTwo.csproj", 32 | "/property:GenerateFullPaths=true", 33 | "/consoleloggerparameters:NoSummary" 34 | ], 35 | "problemMatcher": "$msCompile" 36 | }, 37 | { 38 | "label": "watch:FunctionTwo", 39 | "command": "dotnet", 40 | "type": "process", 41 | "args": [ 42 | "watch", 43 | "run", 44 | "--project", 45 | "${workspaceFolder}/apps/src/FunctionTwo/FunctionTwo.csproj" 46 | ], 47 | "problemMatcher": "$msCompile" 48 | }, 49 | { 50 | "label": "clean:FunctionThree", 51 | "command": "rm", 52 | "type": "shell", 53 | "args": [ 54 | "-rf", 55 | "${workspaceFolder}/apps/src/FunctionThree/bin", 56 | "${workspaceFolder}/apps/src/FunctionThree/obj", 57 | ] 58 | }, 59 | { 60 | "label": "build:FunctionThree", 61 | "command": "dotnet", 62 | "type": "process", 63 | "args": [ 64 | "build", 65 | "${workspaceFolder}/apps/src/FunctionThree/FunctionThree.csproj", 66 | "/property:GenerateFullPaths=true", 67 | "/consoleloggerparameters:NoSummary" 68 | ], 69 | "problemMatcher": "$msCompile" 70 | }, 71 | { 72 | "label": "publish:FunctionThree", 73 | "command": "dotnet", 74 | "type": "process", 75 | "args": [ 76 | "publish", 77 | "${workspaceFolder}/apps/src/FunctionThree/FunctionThree.csproj", 78 | "/property:GenerateFullPaths=true", 79 | "/consoleloggerparameters:NoSummary" 80 | ], 81 | "problemMatcher": "$msCompile" 82 | }, 83 | { 84 | "label": "watch:FunctionThree", 85 | "command": "dotnet", 86 | "type": "process", 87 | "args": [ 88 | "watch", 89 | "run", 90 | "--project", 91 | "${workspaceFolder}/apps/src/FunctionThree/FunctionThree.csproj" 92 | ], 93 | "problemMatcher": "$msCompile" 94 | }, 95 | { 96 | "label": "clean:FunctionOne", 97 | "command": "rm", 98 | "type": "shell", 99 | "args": [ 100 | "-rf", 101 | "${workspaceFolder}/apps/src/FunctionOne/bin", 102 | "${workspaceFolder}/apps/src/FunctionOne/obj", 103 | ] 104 | }, 105 | { 106 | "label": "build:FunctionOne", 107 | "command": "dotnet", 108 | "type": "process", 109 | "args": [ 110 | "build", 111 | "${workspaceFolder}/apps/src/FunctionOne/FunctionOne.csproj", 112 | "/property:GenerateFullPaths=true", 113 | "/consoleloggerparameters:NoSummary" 114 | ], 115 | "problemMatcher": "$msCompile" 116 | }, 117 | { 118 | "label": "publish:FunctionOne", 119 | "command": "dotnet", 120 | "type": "process", 121 | "args": [ 122 | "publish", 123 | "${workspaceFolder}/apps/src/FunctionOne/FunctionOne.csproj", 124 | "/property:GenerateFullPaths=true", 125 | "/consoleloggerparameters:NoSummary" 126 | ], 127 | "problemMatcher": "$msCompile" 128 | }, 129 | { 130 | "label": "watch:FunctionOne", 131 | "command": "dotnet", 132 | "type": "process", 133 | "args": [ 134 | "watch", 135 | "run", 136 | "--project", 137 | "${workspaceFolder}/apps/src/FunctionOne/FunctionOne.csproj" 138 | ], 139 | "problemMatcher": "$msCompile" 140 | }, 141 | { 142 | "label": "build:ALL", 143 | "type": "shell", 144 | "command": "echo 'Build all projects'", 145 | "dependsOn": [ 146 | "build:FunctionOne", 147 | "build:FunctionTwo", 148 | "build:FunctionThree" 149 | ], 150 | "problemMatcher": [], 151 | "group": { 152 | "kind": "build", 153 | "isDefault": true 154 | } 155 | }, 156 | { 157 | "label": "clean:ALL", 158 | "type": "shell", 159 | "command": "echo 'Build all projects'", 160 | "dependsOn": [ 161 | "clean:FunctionOne", 162 | "clean:FunctionTwo", 163 | "clean:FunctionThree" 164 | ], 165 | "problemMatcher": [], 166 | "group": { 167 | "kind": "build", 168 | "isDefault": true 169 | } 170 | } 171 | ] 172 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *main* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | -------------------------------------------------------------------------------- /DemoSolution.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30114.105 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "apps", "apps", "{A9FDE1B6-08C5-496C-8F8C-69267E88A3C8}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7417912E-0908-484A-87B4-D127CEFC0ED6}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionOne", "apps\src\FunctionOne\FunctionOne.csproj", "{F3D14669-86D7-43A5-91FB-A776CF077552}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionTwo", "apps\src\FunctionTwo\FunctionTwo.csproj", "{4C3EA459-D9DC-46FD-8898-D864B5C823C3}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionThree", "apps\src\FunctionThree\FunctionThree.csproj", "{9B5DC817-C267-4228-BAC2-CF505A6269B5}" 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "infra", "infra", "{EDD346FF-0655-48FA-88B8-9A8BBBD9C1DF}" 17 | EndProject 18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{18CB6356-4B69-4ED6-8BE6-B32767853429}" 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infra", "infra\src\Infra\Infra.csproj", "{399006EF-B58E-4E95-B5A0-9C01802BCBC6}" 21 | EndProject 22 | Global 23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 24 | Debug|Any CPU = Debug|Any CPU 25 | Release|Any CPU = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {F3D14669-86D7-43A5-91FB-A776CF077552}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {F3D14669-86D7-43A5-91FB-A776CF077552}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {F3D14669-86D7-43A5-91FB-A776CF077552}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {F3D14669-86D7-43A5-91FB-A776CF077552}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {4C3EA459-D9DC-46FD-8898-D864B5C823C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {4C3EA459-D9DC-46FD-8898-D864B5C823C3}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {4C3EA459-D9DC-46FD-8898-D864B5C823C3}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {4C3EA459-D9DC-46FD-8898-D864B5C823C3}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {9B5DC817-C267-4228-BAC2-CF505A6269B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {9B5DC817-C267-4228-BAC2-CF505A6269B5}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {9B5DC817-C267-4228-BAC2-CF505A6269B5}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {9B5DC817-C267-4228-BAC2-CF505A6269B5}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {399006EF-B58E-4E95-B5A0-9C01802BCBC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {399006EF-B58E-4E95-B5A0-9C01802BCBC6}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {399006EF-B58E-4E95-B5A0-9C01802BCBC6}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {399006EF-B58E-4E95-B5A0-9C01802BCBC6}.Release|Any CPU.Build.0 = Release|Any CPU 47 | EndGlobalSection 48 | GlobalSection(NestedProjects) = preSolution 49 | {7417912E-0908-484A-87B4-D127CEFC0ED6} = {A9FDE1B6-08C5-496C-8F8C-69267E88A3C8} 50 | {F3D14669-86D7-43A5-91FB-A776CF077552} = {7417912E-0908-484A-87B4-D127CEFC0ED6} 51 | {4C3EA459-D9DC-46FD-8898-D864B5C823C3} = {7417912E-0908-484A-87B4-D127CEFC0ED6} 52 | {9B5DC817-C267-4228-BAC2-CF505A6269B5} = {7417912E-0908-484A-87B4-D127CEFC0ED6} 53 | {18CB6356-4B69-4ED6-8BE6-B32767853429} = {EDD346FF-0655-48FA-88B8-9A8BBBD9C1DF} 54 | {399006EF-B58E-4E95-B5A0-9C01802BCBC6} = {18CB6356-4B69-4ED6-8BE6-B32767853429} 55 | EndGlobalSection 56 | EndGlobal 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 10 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 11 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 12 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Build, package, and publish .NET C# Lambda functions with the AWS CDK 2 | 3 | This Repository contents sample source code that shows how to streamline building, packaging, and publishing .NET Lambda functions using AWS CDK with C#. 4 | 5 | ## Implementation and Deployment 6 | 7 | **Prerequisites:** 8 | 9 | 1. [Visual Studio Code](https://code.visualstudio.com/download) (or your preferred IDE). 10 | 1. [AWS account](aws.amazon.com/). 11 | 1. [.NET 6 SDK](https://dotnet.microsoft.com/en-us/download/dotnet) 12 | 1. AWS Cloud Development Kit (CDK) (). 13 | 1. GIT (). 14 | 1. Docker 15 | 16 | To learn how to implement CDK C# to build, package and publish lambda code follow the implementation on the file [infra/src/Infra/InfraStack.cs](infra/src/Infra/InfraStack.cs). 17 | 18 | Execute the following commands to deploy and test the solution 19 | 20 | **Deploy:** 21 | 22 | ```bash 23 | cd /infra 24 | cdk deploy --profile 25 | ``` 26 | 27 | **Test:** 28 | 29 | Once the deployment is complete, copy the endpoint from the terminal output and make HTTP GET Request. The format of the endpoint should be similar to https://xxxyyyzzz.execute-api.us-east-1.amazonaws.com/prod/. 30 | 31 | ```bash 32 | curl https://xxxyyyzzz.execute-api.us-west-2.amazonaws.com/prod/ 33 | curl https://xxxyyyzzz.execute-api.us-west-2.amazonaws.com/prod/functiontwo 34 | curl https://xxxyyyzzz.execute-api.us-west-2.amazonaws.com/prod/functionthree 35 | ``` 36 | 37 | ## References 38 | 39 | To learn more about the implementation read the blog post [Build, package, and publish .NET C# Lambda functions with the AWS CDK](https://aws-blogs-prod.amazon.com/modernizing-with-aws/build-package-pu…unctions-aws-cdk) 40 | 41 | ## Security 42 | 43 | See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. 44 | 45 | ## License 46 | 47 | This library is licensed under the MIT-0 License. See the LICENSE file. 48 | -------------------------------------------------------------------------------- /Ste-by-step-guide.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | This guide content the step-by-step to help you re-create similar project structure like this one. 4 | 5 | ## Prerequisite Tools 6 | 7 | ## How does these project got created? 8 | 9 | To recreate this same project structure, make sure you've all the prerequisite tools installed and execute the following commands 10 | 1. Install the Amazon.Lambda.Templates from nuget 11 | dotnet new install Amazon.Lambda.Templates 12 | 2. Create the Minimal API ASP.NET6 C# Lambda Function 13 | 14 | ```bash 15 | mkdir apps 16 | cd apps 17 | dotnet new serverless.AspNetCoreMinimalAPI -o ./ --name FunctionOne 18 | dotnet new serverless.AspNetCoreMinimalAPI -o ./ --name FunctionTwo 19 | dotnet new serverless.AspNetCoreMinimalAPI -o ./ --name FunctionThree 20 | cd .. 21 | ``` 22 | 23 | 3. Create the .NET CDK project for Infrastructure as Code 24 | 25 | ```bash 26 | mkdir infra 27 | cd infra 28 | cdk init app --language=csharp 29 | cd .. 30 | ``` 31 | 32 | 4. Create the Visual Studio Solution file and add the Apps and Infra projects to the Solution 33 | 34 | ```bash 35 | dotnet new sln --name DemoSolution 36 | dotnet sln add DemoSolution.sln ./apps/src/FunctionOne/FunctionOne.csproj 37 | dotnet sln add DemoSolution.sln ./apps/src/FunctionTwo/FunctionTwo.csproj 38 | dotnet sln add DemoSolution.sln ./apps/src/FunctionThree/FunctionThree.csproj 39 | dotnet sln add DemoSolution.sln ./infra/src/Infra/Infra.csproj 40 | ``` 41 | -------------------------------------------------------------------------------- /apps/src/FunctionOne/Controllers/CalculatorController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace FunctionOne.Controllers; 4 | 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class CalculatorController : ControllerBase 8 | { 9 | private readonly ILogger _logger; 10 | 11 | public CalculatorController(ILogger logger) 12 | { 13 | _logger = logger; 14 | } 15 | 16 | // GET calculator/add/4/2/ 17 | [HttpGet("add/{x}/{y}")] 18 | public int Add(int x, int y) 19 | { 20 | _logger.LogInformation($"{x} plus {y} is {x + y}"); 21 | return x + y; 22 | } 23 | 24 | // GET calculator/substract/4/2/ 25 | [HttpGet("subtract/{x}/{y}")] 26 | public int Subtract(int x, int y) 27 | { 28 | _logger.LogInformation($"{x} subtract {y} is {x - y}"); 29 | return x - y; 30 | } 31 | 32 | // GET calculator/multiply/4/2/ 33 | [HttpGet("multiply/{x}/{y}")] 34 | public int Multiply(int x, int y) 35 | { 36 | _logger.LogInformation($"{x} multiply {y} is {x * y}"); 37 | return x * y; 38 | } 39 | 40 | // GET calculator/divide/4/2/ 41 | [HttpGet("divide/{x}/{y}")] 42 | public int Divide(int x, int y) 43 | { 44 | _logger.LogInformation($"{x} divide {y} is {x / y}"); 45 | return x / y; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /apps/src/FunctionOne/FunctionOne.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | enable 5 | enable 6 | true 7 | Lambda 8 | 10 | true 11 | 12 | true 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /apps/src/FunctionOne/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | builder.Services.AddControllers(); 5 | 6 | // Add AWS Lambda support. When application is run in Lambda Kestrel is swapped out as the web server with Amazon.Lambda.AspNetCoreServer. This 7 | // package will act as the webserver translating request and responses between the Lambda event source and ASP.NET Core. 8 | builder.Services.AddAWSLambdaHosting(LambdaEventSource.RestApi); 9 | 10 | var app = builder.Build(); 11 | 12 | 13 | app.UseHttpsRedirection(); 14 | app.UseAuthorization(); 15 | app.MapControllers(); 16 | 17 | app.MapGet("/", () => "Welcome to running ASP.NET Core Minimal API on AWS Lambda - Function One!"); 18 | 19 | app.Run(); 20 | -------------------------------------------------------------------------------- /apps/src/FunctionOne/Readme.md: -------------------------------------------------------------------------------- 1 | # ASP.NET Core Minimal API Serverless Application 2 | 3 | This project shows how to run an ASP.NET Core Web API project as an AWS Lambda exposed through Amazon API Gateway. The NuGet package [Amazon.Lambda.AspNetCoreServer](https://www.nuget.org/packages/Amazon.Lambda.AspNetCoreServer) contains a Lambda function that is used to translate requests from API Gateway into the ASP.NET Core framework and then the responses from ASP.NET Core back to API Gateway. 4 | 5 | 6 | For more information about how the Amazon.Lambda.AspNetCoreServer package works and how to extend its behavior view its [README](https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.AspNetCoreServer/README.md) file in GitHub. 7 | 8 | ## Executable Assembly ## 9 | 10 | .NET Lambda projects that use C# top level statements like this project must be deployed as an executable assembly instead of a class library. To indicate to Lambda that the .NET function is an executable assembly the 11 | Lambda function handler value is set to the .NET Assembly name. This is different then deploying as a class library where the function handler string includes the assembly, type and method name. 12 | 13 | To deploy as an executable assembly the Lambda runtime client must be started to listen for incoming events to process. For an ASP.NET Core application the Lambda runtime client is started by included the 14 | `Amazon.Lambda.AspNetCoreServer.Hosting` NuGet package and calling `AddAWSLambdaHosting(LambdaEventSource.HttpApi)` passing in the event source while configuring the services of the application. The 15 | event source can be API Gateway REST API and HTTP API or Application Load Balancer. 16 | 17 | ### Project Files ### 18 | 19 | * serverless.template - an AWS CloudFormation Serverless Application Model template file for declaring your Serverless functions and other AWS resources 20 | * aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS 21 | * Program.cs - entry point to the application that contains all of the top level statements initializing the ASP.NET Core application. 22 | The call to `AddAWSLambdaHosting` configures the application to work in Lambda when it detects Lambda is the executing environment. 23 | * Controllers\CalculatorController - example Web API controller 24 | 25 | You may also have a test project depending on the options selected. 26 | 27 | ## Here are some steps to follow from Visual Studio: 28 | 29 | To deploy your Serverless application, right click the project in Solution Explorer and select *Publish to AWS Lambda*. 30 | 31 | To view your deployed application open the Stack View window by double-clicking the stack name shown beneath the AWS CloudFormation node in the AWS Explorer tree. The Stack View also displays the root URL to your published application. 32 | 33 | ## Here are some steps to follow to get started from the command line: 34 | 35 | Once you have edited your template and code you can deploy your application using the [Amazon.Lambda.Tools Global Tool](https://github.com/aws/aws-extensions-for-dotnet-cli#aws-lambda-amazonlambdatools) from the command line. 36 | 37 | Install Amazon.Lambda.Tools Global Tools if not already installed. 38 | ``` 39 | dotnet tool install -g Amazon.Lambda.Tools 40 | ``` 41 | 42 | If already installed check if new version is available. 43 | ``` 44 | dotnet tool update -g Amazon.Lambda.Tools 45 | ``` 46 | 47 | Deploy application 48 | ``` 49 | cd "FunctionOne/src/FunctionOne" 50 | dotnet lambda deploy-serverless 51 | ``` 52 | -------------------------------------------------------------------------------- /apps/src/FunctionOne/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /apps/src/FunctionOne/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } -------------------------------------------------------------------------------- /apps/src/FunctionOne/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "Information": [ 3 | "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", 4 | "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.", 5 | "dotnet lambda help", 6 | "All the command line options for the Lambda command can be specified in this file." 7 | ], 8 | "profile": "", 9 | "region": "", 10 | "configuration": "Release", 11 | "s3-prefix": "FunctionOne/", 12 | "template": "serverless.template", 13 | "template-parameters": "" 14 | } -------------------------------------------------------------------------------- /apps/src/FunctionThree/Controllers/CalculatorController.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace FunctionThree.Controllers; 5 | 6 | [ApiController] 7 | [Route("[controller]")] 8 | public class CalculatorController : ControllerBase 9 | { 10 | private readonly ILogger _logger; 11 | 12 | public CalculatorController(ILogger logger) 13 | { 14 | _logger = logger; 15 | } 16 | 17 | // GET calculator/add/4/2/ 18 | [HttpGet("add/{x}/{y}")] 19 | public int Add(int x, int y) 20 | { 21 | _logger.LogInformation($"{x} plus {y} is {x + y}"); 22 | return x + y; 23 | } 24 | 25 | // GET calculator/substract/4/2/ 26 | [HttpGet("subtract/{x}/{y}")] 27 | public int Subtract(int x, int y) 28 | { 29 | _logger.LogInformation($"{x} subtract {y} is {x - y}"); 30 | return x - y; 31 | } 32 | 33 | // GET calculator/multiply/4/2/ 34 | [HttpGet("multiply/{x}/{y}")] 35 | public int Multiply(int x, int y) 36 | { 37 | _logger.LogInformation($"{x} multiply {y} is {x * y}"); 38 | return x * y; 39 | } 40 | 41 | // GET calculator/divide/4/2/ 42 | [HttpGet("divide/{x}/{y}")] 43 | public int Divide(int x, int y) 44 | { 45 | _logger.LogInformation($"{x} divide {y} is {x / y}"); 46 | return x / y; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /apps/src/FunctionThree/FunctionThree.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | enable 5 | enable 6 | true 7 | Lambda 8 | 10 | true 11 | 12 | true 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /apps/src/FunctionThree/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | builder.Services.AddControllers(); 5 | 6 | // Add AWS Lambda support. When application is run in Lambda Kestrel is swapped out as the web server with Amazon.Lambda.AspNetCoreServer. This 7 | // package will act as the webserver translating request and responses between the Lambda event source and ASP.NET Core. 8 | builder.Services.AddAWSLambdaHosting(LambdaEventSource.RestApi); 9 | 10 | var app = builder.Build(); 11 | 12 | 13 | app.UseHttpsRedirection(); 14 | app.UseAuthorization(); 15 | app.MapControllers(); 16 | 17 | app.UsePathBase(new PathString("/functionthree")); 18 | app.MapGet("/", () => "Welcome to running ASP.NET Core Minimal API on AWS Lambda - Function Three!"); 19 | app.UseRouting(); 20 | 21 | app.Run(); 22 | -------------------------------------------------------------------------------- /apps/src/FunctionThree/Readme.md: -------------------------------------------------------------------------------- 1 | # ASP.NET Core Minimal API Serverless Application 2 | 3 | This project shows how to run an ASP.NET Core Web API project as an AWS Lambda exposed through Amazon API Gateway. The NuGet package [Amazon.Lambda.AspNetCoreServer](https://www.nuget.org/packages/Amazon.Lambda.AspNetCoreServer) contains a Lambda function that is used to translate requests from API Gateway into the ASP.NET Core framework and then the responses from ASP.NET Core back to API Gateway. 4 | 5 | 6 | For more information about how the Amazon.Lambda.AspNetCoreServer package works and how to extend its behavior view its [README](https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.AspNetCoreServer/README.md) file in GitHub. 7 | 8 | ## Executable Assembly ## 9 | 10 | .NET Lambda projects that use C# top level statements like this project must be deployed as an executable assembly instead of a class library. To indicate to Lambda that the .NET function is an executable assembly the 11 | Lambda function handler value is set to the .NET Assembly name. This is different then deploying as a class library where the function handler string includes the assembly, type and method name. 12 | 13 | To deploy as an executable assembly the Lambda runtime client must be started to listen for incoming events to process. For an ASP.NET Core application the Lambda runtime client is started by included the 14 | `Amazon.Lambda.AspNetCoreServer.Hosting` NuGet package and calling `AddAWSLambdaHosting(LambdaEventSource.HttpApi)` passing in the event source while configuring the services of the application. The 15 | event source can be API Gateway REST API and HTTP API or Application Load Balancer. 16 | 17 | ### Project Files ### 18 | 19 | * serverless.template - an AWS CloudFormation Serverless Application Model template file for declaring your Serverless functions and other AWS resources 20 | * aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS 21 | * Program.cs - entry point to the application that contains all of the top level statements initializing the ASP.NET Core application. 22 | The call to `AddAWSLambdaHosting` configures the application to work in Lambda when it detects Lambda is the executing environment. 23 | * Controllers\CalculatorController - example Web API controller 24 | 25 | You may also have a test project depending on the options selected. 26 | 27 | ## Here are some steps to follow from Visual Studio: 28 | 29 | To deploy your Serverless application, right click the project in Solution Explorer and select *Publish to AWS Lambda*. 30 | 31 | To view your deployed application open the Stack View window by double-clicking the stack name shown beneath the AWS CloudFormation node in the AWS Explorer tree. The Stack View also displays the root URL to your published application. 32 | 33 | ## Here are some steps to follow to get started from the command line: 34 | 35 | Once you have edited your template and code you can deploy your application using the [Amazon.Lambda.Tools Global Tool](https://github.com/aws/aws-extensions-for-dotnet-cli#aws-lambda-amazonlambdatools) from the command line. 36 | 37 | Install Amazon.Lambda.Tools Global Tools if not already installed. 38 | ``` 39 | dotnet tool install -g Amazon.Lambda.Tools 40 | ``` 41 | 42 | If already installed check if new version is available. 43 | ``` 44 | dotnet tool update -g Amazon.Lambda.Tools 45 | ``` 46 | 47 | Deploy application 48 | ``` 49 | cd "FunctionThree/src/FunctionThree" 50 | dotnet lambda deploy-serverless 51 | ``` 52 | -------------------------------------------------------------------------------- /apps/src/FunctionThree/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /apps/src/FunctionThree/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } -------------------------------------------------------------------------------- /apps/src/FunctionThree/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "Information": [ 3 | "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", 4 | "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.", 5 | "dotnet lambda help", 6 | "All the command line options for the Lambda command can be specified in this file." 7 | ], 8 | "profile": "", 9 | "region": "", 10 | "configuration": "Release", 11 | "s3-prefix": "FunctionThree/", 12 | "template": "serverless.template", 13 | "template-parameters": "" 14 | } -------------------------------------------------------------------------------- /apps/src/FunctionTwo/Controllers/CalculatorController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace FunctionTwo.Controllers; 4 | 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class CalculatorController : ControllerBase 8 | { 9 | private readonly ILogger _logger; 10 | 11 | public CalculatorController(ILogger logger) 12 | { 13 | _logger = logger; 14 | } 15 | 16 | // GET calculator/add/4/2/ 17 | [HttpGet("add/{x}/{y}")] 18 | public int Add(int x, int y) 19 | { 20 | _logger.LogInformation($"{x} plus {y} is {x + y}"); 21 | return x + y; 22 | } 23 | 24 | // GET calculator/substract/4/2/ 25 | [HttpGet("subtract/{x}/{y}")] 26 | public int Subtract(int x, int y) 27 | { 28 | _logger.LogInformation($"{x} subtract {y} is {x - y}"); 29 | return x - y; 30 | } 31 | 32 | // GET calculator/multiply/4/2/ 33 | [HttpGet("multiply/{x}/{y}")] 34 | public int Multiply(int x, int y) 35 | { 36 | _logger.LogInformation($"{x} multiply {y} is {x * y}"); 37 | return x * y; 38 | } 39 | 40 | // GET calculator/divide/4/2/ 41 | [HttpGet("divide/{x}/{y}")] 42 | public int Divide(int x, int y) 43 | { 44 | _logger.LogInformation($"{x} divide {y} is {x / y}"); 45 | return x / y; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /apps/src/FunctionTwo/FunctionTwo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | enable 5 | enable 6 | true 7 | Lambda 8 | 10 | true 11 | 12 | true 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /apps/src/FunctionTwo/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | builder.Services.AddControllers(); 5 | 6 | // Add AWS Lambda support. When application is run in Lambda Kestrel is swapped out as the web server with Amazon.Lambda.AspNetCoreServer. This 7 | // package will act as the webserver translating request and responses between the Lambda event source and ASP.NET Core. 8 | builder.Services.AddAWSLambdaHosting(LambdaEventSource.RestApi); 9 | 10 | var app = builder.Build(); 11 | 12 | 13 | app.UseHttpsRedirection(); 14 | app.UseAuthorization(); 15 | app.MapControllers(); 16 | 17 | app.UsePathBase(new PathString("/functiontwo")); 18 | app.MapGet("/", () => "Welcome to running ASP.NET Core Minimal API on AWS Lambda - Function Two!"); 19 | app.UseRouting(); 20 | 21 | app.Run(); 22 | -------------------------------------------------------------------------------- /apps/src/FunctionTwo/Readme.md: -------------------------------------------------------------------------------- 1 | # ASP.NET Core Minimal API Serverless Application 2 | 3 | This project shows how to run an ASP.NET Core Web API project as an AWS Lambda exposed through Amazon API Gateway. The NuGet package [Amazon.Lambda.AspNetCoreServer](https://www.nuget.org/packages/Amazon.Lambda.AspNetCoreServer) contains a Lambda function that is used to translate requests from API Gateway into the ASP.NET Core framework and then the responses from ASP.NET Core back to API Gateway. 4 | 5 | 6 | For more information about how the Amazon.Lambda.AspNetCoreServer package works and how to extend its behavior view its [README](https://github.com/aws/aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.AspNetCoreServer/README.md) file in GitHub. 7 | 8 | ## Executable Assembly ## 9 | 10 | .NET Lambda projects that use C# top level statements like this project must be deployed as an executable assembly instead of a class library. To indicate to Lambda that the .NET function is an executable assembly the 11 | Lambda function handler value is set to the .NET Assembly name. This is different then deploying as a class library where the function handler string includes the assembly, type and method name. 12 | 13 | To deploy as an executable assembly the Lambda runtime client must be started to listen for incoming events to process. For an ASP.NET Core application the Lambda runtime client is started by included the 14 | `Amazon.Lambda.AspNetCoreServer.Hosting` NuGet package and calling `AddAWSLambdaHosting(LambdaEventSource.HttpApi)` passing in the event source while configuring the services of the application. The 15 | event source can be API Gateway REST API and HTTP API or Application Load Balancer. 16 | 17 | ### Project Files ### 18 | 19 | * serverless.template - an AWS CloudFormation Serverless Application Model template file for declaring your Serverless functions and other AWS resources 20 | * aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS 21 | * Program.cs - entry point to the application that contains all of the top level statements initializing the ASP.NET Core application. 22 | The call to `AddAWSLambdaHosting` configures the application to work in Lambda when it detects Lambda is the executing environment. 23 | * Controllers\CalculatorController - example Web API controller 24 | 25 | You may also have a test project depending on the options selected. 26 | 27 | ## Here are some steps to follow from Visual Studio: 28 | 29 | To deploy your Serverless application, right click the project in Solution Explorer and select *Publish to AWS Lambda*. 30 | 31 | To view your deployed application open the Stack View window by double-clicking the stack name shown beneath the AWS CloudFormation node in the AWS Explorer tree. The Stack View also displays the root URL to your published application. 32 | 33 | ## Here are some steps to follow to get started from the command line: 34 | 35 | Once you have edited your template and code you can deploy your application using the [Amazon.Lambda.Tools Global Tool](https://github.com/aws/aws-extensions-for-dotnet-cli#aws-lambda-amazonlambdatools) from the command line. 36 | 37 | Install Amazon.Lambda.Tools Global Tools if not already installed. 38 | ``` 39 | dotnet tool install -g Amazon.Lambda.Tools 40 | ``` 41 | 42 | If already installed check if new version is available. 43 | ``` 44 | dotnet tool update -g Amazon.Lambda.Tools 45 | ``` 46 | 47 | Deploy application 48 | ``` 49 | cd "FunctionTwo/src/FunctionTwo" 50 | dotnet lambda deploy-serverless 51 | ``` 52 | -------------------------------------------------------------------------------- /apps/src/FunctionTwo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /apps/src/FunctionTwo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } -------------------------------------------------------------------------------- /apps/src/FunctionTwo/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "Information": [ 3 | "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", 4 | "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.", 5 | "dotnet lambda help", 6 | "All the command line options for the Lambda command can be specified in this file." 7 | ], 8 | "profile": "", 9 | "region": "", 10 | "configuration": "Release", 11 | "s3-prefix": "FunctionTwo/", 12 | "template": "serverless.template", 13 | "template-parameters": "" 14 | } -------------------------------------------------------------------------------- /infra/.gitignore: -------------------------------------------------------------------------------- 1 | # CDK asset staging directory 2 | .cdk.staging 3 | cdk.out 4 | 5 | # Created by https://www.gitignore.io/api/csharp 6 | 7 | ### Csharp ### 8 | ## Ignore Visual Studio temporary files, build results, and 9 | ## files generated by popular Visual Studio add-ons. 10 | ## 11 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 12 | 13 | # User-specific files 14 | *.suo 15 | *.user 16 | *.userosscache 17 | *.sln.docstates 18 | 19 | # User-specific files (MonoDevelop/Xamarin Studio) 20 | *.userprefs 21 | 22 | # Build results 23 | [Dd]ebug/ 24 | [Dd]ebugPublic/ 25 | [Rr]elease/ 26 | [Rr]eleases/ 27 | x64/ 28 | x86/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUNIT 47 | *.VisualState.xml 48 | TestResult.xml 49 | 50 | # Build Results of an ATL Project 51 | [Dd]ebugPS/ 52 | [Rr]eleasePS/ 53 | dlldata.c 54 | 55 | # Benchmark Results 56 | BenchmarkDotNet.Artifacts/ 57 | 58 | # .NET Core 59 | project.lock.json 60 | project.fragment.lock.json 61 | artifacts/ 62 | 63 | # StyleCop 64 | StyleCopReport.xml 65 | 66 | # Files built by Visual Studio 67 | *_i.c 68 | *_p.c 69 | *_i.h 70 | *.ilk 71 | *.meta 72 | *.obj 73 | *.iobj 74 | *.pch 75 | *.pdb 76 | *.ipdb 77 | *.pgc 78 | *.pgd 79 | *.rsp 80 | *.sbr 81 | *.tlb 82 | *.tli 83 | *.tlh 84 | *.tmp 85 | *.tmp_proj 86 | *.log 87 | *.vspscc 88 | *.vssscc 89 | .builds 90 | *.pidb 91 | *.svclog 92 | *.scc 93 | 94 | # Chutzpah Test files 95 | _Chutzpah* 96 | 97 | # Visual C++ cache files 98 | ipch/ 99 | *.aps 100 | *.ncb 101 | *.opendb 102 | *.opensdf 103 | *.sdf 104 | *.cachefile 105 | *.VC.db 106 | *.VC.VC.opendb 107 | 108 | # Visual Studio profiler 109 | *.psess 110 | *.vsp 111 | *.vspx 112 | *.sap 113 | 114 | # Visual Studio Trace Files 115 | *.e2e 116 | 117 | # TFS 2012 Local Workspace 118 | $tf/ 119 | 120 | # Guidance Automation Toolkit 121 | *.gpState 122 | 123 | # ReSharper is a .NET coding add-in 124 | _ReSharper*/ 125 | *.[Rr]e[Ss]harper 126 | *.DotSettings.user 127 | 128 | # JustCode is a .NET coding add-in 129 | .JustCode 130 | 131 | # TeamCity is a build add-in 132 | _TeamCity* 133 | 134 | # DotCover is a Code Coverage Tool 135 | *.dotCover 136 | 137 | # AxoCover is a Code Coverage Tool 138 | .axoCover/* 139 | !.axoCover/settings.json 140 | 141 | # Visual Studio code coverage results 142 | *.coverage 143 | *.coveragexml 144 | 145 | # NCrunch 146 | _NCrunch_* 147 | .*crunch*.local.xml 148 | nCrunchTemp_* 149 | 150 | # MightyMoose 151 | *.mm.* 152 | AutoTest.Net/ 153 | 154 | # Web workbench (sass) 155 | .sass-cache/ 156 | 157 | # Installshield output folder 158 | [Ee]xpress/ 159 | 160 | # DocProject is a documentation generator add-in 161 | DocProject/buildhelp/ 162 | DocProject/Help/*.HxT 163 | DocProject/Help/*.HxC 164 | DocProject/Help/*.hhc 165 | DocProject/Help/*.hhk 166 | DocProject/Help/*.hhp 167 | DocProject/Help/Html2 168 | DocProject/Help/html 169 | 170 | # Click-Once directory 171 | publish/ 172 | 173 | # Publish Web Output 174 | *.[Pp]ublish.xml 175 | *.azurePubxml 176 | # Note: Comment the next line if you want to checkin your web deploy settings, 177 | # but database connection strings (with potential passwords) will be unencrypted 178 | *.pubxml 179 | *.publishproj 180 | 181 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 182 | # checkin your Azure Web App publish settings, but sensitive information contained 183 | # in these scripts will be unencrypted 184 | PublishScripts/ 185 | 186 | # NuGet Packages 187 | *.nupkg 188 | # The packages folder can be ignored because of Package Restore 189 | **/[Pp]ackages/* 190 | # except build/, which is used as an MSBuild target. 191 | !**/[Pp]ackages/build/ 192 | # Uncomment if necessary however generally it will be regenerated when needed 193 | #!**/[Pp]ackages/repositories.config 194 | # NuGet v3's project.json files produces more ignorable files 195 | *.nuget.props 196 | *.nuget.targets 197 | 198 | # Microsoft Azure Build Output 199 | csx/ 200 | *.build.csdef 201 | 202 | # Microsoft Azure Emulator 203 | ecf/ 204 | rcf/ 205 | 206 | # Windows Store app package directories and files 207 | AppPackages/ 208 | BundleArtifacts/ 209 | Package.StoreAssociation.xml 210 | _pkginfo.txt 211 | *.appx 212 | 213 | # Visual Studio cache files 214 | # files ending in .cache can be ignored 215 | *.[Cc]ache 216 | # but keep track of directories ending in .cache 217 | !*.[Cc]ache/ 218 | 219 | # Others 220 | ClientBin/ 221 | ~$* 222 | *~ 223 | *.dbmdl 224 | *.dbproj.schemaview 225 | *.jfm 226 | *.pfx 227 | *.publishsettings 228 | orleans.codegen.cs 229 | 230 | # Including strong name files can present a security risk 231 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 232 | #*.snk 233 | 234 | # Since there are multiple workflows, uncomment next line to ignore bower_components 235 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 236 | #bower_components/ 237 | 238 | # RIA/Silverlight projects 239 | Generated_Code/ 240 | 241 | # Backup & report files from converting an old project file 242 | # to a newer Visual Studio version. Backup files are not needed, 243 | # because we have git ;-) 244 | _UpgradeReport_Files/ 245 | Backup*/ 246 | UpgradeLog*.XML 247 | UpgradeLog*.htm 248 | ServiceFabricBackup/ 249 | *.rptproj.bak 250 | 251 | # SQL Server files 252 | *.mdf 253 | *.ldf 254 | *.ndf 255 | 256 | # Business Intelligence projects 257 | *.rdl.data 258 | *.bim.layout 259 | *.bim_*.settings 260 | *.rptproj.rsuser 261 | 262 | # Microsoft Fakes 263 | FakesAssemblies/ 264 | 265 | # GhostDoc plugin setting file 266 | *.GhostDoc.xml 267 | 268 | # Node.js Tools for Visual Studio 269 | .ntvs_analysis.dat 270 | node_modules/ 271 | 272 | # Visual Studio 6 build log 273 | *.plg 274 | 275 | # Visual Studio 6 workspace options file 276 | *.opt 277 | 278 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 279 | *.vbw 280 | 281 | # Visual Studio LightSwitch build output 282 | **/*.HTMLClient/GeneratedArtifacts 283 | **/*.DesktopClient/GeneratedArtifacts 284 | **/*.DesktopClient/ModelManifest.xml 285 | **/*.Server/GeneratedArtifacts 286 | **/*.Server/ModelManifest.xml 287 | _Pvt_Extensions 288 | 289 | # Paket dependency manager 290 | .paket/paket.exe 291 | paket-files/ 292 | 293 | # FAKE - F# Make 294 | .fake/ 295 | 296 | # JetBrains Rider 297 | .idea/ 298 | *.sln.iml 299 | 300 | # CodeRush 301 | .cr/ 302 | 303 | # Python Tools for Visual Studio (PTVS) 304 | __pycache__/ 305 | *.pyc 306 | 307 | # Cake - Uncomment if you are using it 308 | # tools/** 309 | # !tools/packages.config 310 | 311 | # Tabs Studio 312 | *.tss 313 | 314 | # Telerik's JustMock configuration file 315 | *.jmconfig 316 | 317 | # BizTalk build output 318 | *.btp.cs 319 | *.btm.cs 320 | *.odx.cs 321 | *.xsd.cs 322 | 323 | # OpenCover UI analysis results 324 | OpenCover/ 325 | 326 | # Azure Stream Analytics local run output 327 | ASALocalRun/ 328 | 329 | # MSBuild Binary and Structured Log 330 | *.binlog 331 | 332 | # NVidia Nsight GPU debugger configuration file 333 | *.nvuser 334 | 335 | # MFractors (Xamarin productivity tool) working folder 336 | .mfractor/ 337 | 338 | # Local History for Visual Studio 339 | .localhistory/ 340 | 341 | 342 | # End of https://www.gitignore.io/api/csharp -------------------------------------------------------------------------------- /infra/README.md: -------------------------------------------------------------------------------- 1 | # Welcome to your CDK C# project! 2 | 3 | This is a blank project for CDK development with C#. 4 | 5 | The `cdk.json` file tells the CDK Toolkit how to execute your app. 6 | 7 | It uses the [.NET Core CLI](https://docs.microsoft.com/dotnet/articles/core/) to compile and execute your project. 8 | 9 | ## Useful commands 10 | 11 | * `dotnet build src` compile this app 12 | * `cdk deploy` deploy this stack to your default AWS account/region 13 | * `cdk diff` compare deployed stack with current state 14 | * `cdk synth` emits the synthesized CloudFormation template -------------------------------------------------------------------------------- /infra/cdk.json: -------------------------------------------------------------------------------- 1 | { 2 | "app": "dotnet run --project src/Infra/Infra.csproj", 3 | "watch": { 4 | "include": [ 5 | "**" 6 | ], 7 | "exclude": [ 8 | "README.md", 9 | "cdk*.json", 10 | "src/*/obj", 11 | "src/*/bin", 12 | "src/*.sln", 13 | "src/*/GlobalSuppressions.cs", 14 | "src/*/*.csproj" 15 | ] 16 | }, 17 | "context": { 18 | "@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true, 19 | "@aws-cdk/core:stackRelativeExports": true, 20 | "@aws-cdk/aws-rds:lowercaseDbIdentifier": true, 21 | "@aws-cdk/aws-lambda:recognizeVersionProps": true, 22 | "@aws-cdk/aws-lambda:recognizeLayerVersion": true, 23 | "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true, 24 | "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, 25 | "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, 26 | "@aws-cdk/core:checkSecretUsage": true, 27 | "@aws-cdk/aws-iam:minimizePolicies": true, 28 | "@aws-cdk/core:target-partitions": [ 29 | "aws", 30 | "aws-cn" 31 | ] 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /infra/src/Infra.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26124.0 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infra", "Infra\Infra.csproj", "{AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|x64 = Debug|x64 12 | Debug|x86 = Debug|x86 13 | Release|Any CPU = Release|Any CPU 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Debug|x64.ActiveCfg = Debug|Any CPU 24 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Debug|x64.Build.0 = Debug|Any CPU 25 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Debug|x86.ActiveCfg = Debug|Any CPU 26 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Debug|x86.Build.0 = Debug|Any CPU 27 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Release|Any CPU.Build.0 = Release|Any CPU 29 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Release|x64.ActiveCfg = Release|Any CPU 30 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Release|x64.Build.0 = Release|Any CPU 31 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Release|x86.ActiveCfg = Release|Any CPU 32 | {AFFF70DF-C8EC-45E9-A3ED-252EEF99B71A}.Release|x86.Build.0 = Release|Any CPU 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /infra/src/Infra/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Potential Code Quality Issues", "RECS0026:Possible unassigned object created by 'new'", Justification = "Constructs add themselves to the scope in which they are created")] 2 | -------------------------------------------------------------------------------- /infra/src/Infra/Infra.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | Major 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /infra/src/Infra/InfraStack.cs: -------------------------------------------------------------------------------- 1 | using Amazon.CDK; 2 | using Constructs; 3 | using Amazon.CDK.AWS.APIGateway; 4 | using Amazon.CDK.AWS.Lambda; 5 | using Amazon.CDK.AWS.Logs; 6 | 7 | namespace Infra 8 | { 9 | public class InfraStack : Stack 10 | { 11 | internal InfraStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) 12 | { 13 | var buildOption = new BundlingOptions() 14 | { 15 | Image = Runtime.DOTNET_8.BundlingImage, 16 | User = "root", 17 | OutputType = BundlingOutput.ARCHIVED, 18 | Command = new string[]{ 19 | "/bin/sh", 20 | "-c", 21 | " dotnet tool install -g Amazon.Lambda.Tools"+ 22 | " && dotnet build"+ 23 | " && dotnet lambda package --output-package /asset-output/function.zip" 24 | } 25 | }; 26 | 27 | var lambdaFunctionOne = new Function(this, "my-funcOne", new FunctionProps 28 | { 29 | Runtime = Runtime.DOTNET_8, 30 | MemorySize = 1024, 31 | LogRetention = RetentionDays.ONE_DAY, 32 | Handler = "FunctionOne", 33 | Code = Code.FromAsset("../apps/src/FunctionOne/", new Amazon.CDK.AWS.S3.Assets.AssetOptions 34 | { 35 | Bundling = buildOption 36 | }), 37 | }); 38 | 39 | var lambdaFunctionTwo = new Function(this, "my-funcTwo", new FunctionProps 40 | { 41 | Runtime = Runtime.DOTNET_8, 42 | MemorySize = 1024, 43 | LogRetention = RetentionDays.ONE_DAY, 44 | Handler = "FunctionTwo", 45 | Code = Code.FromAsset("../apps/src/FunctionTwo/", new Amazon.CDK.AWS.S3.Assets.AssetOptions 46 | { 47 | Bundling = buildOption 48 | }), 49 | }); 50 | 51 | var lambdaFunctionThree = new Function(this, "my-funcThree", new FunctionProps 52 | { 53 | Runtime = Runtime.DOTNET_8, 54 | MemorySize = 1024, 55 | LogRetention = RetentionDays.ONE_DAY, 56 | Handler = "FunctionThree", 57 | Code = Code.FromAsset("../apps/src/FunctionThree/", new Amazon.CDK.AWS.S3.Assets.AssetOptions 58 | { 59 | Bundling = buildOption 60 | }), 61 | }); 62 | 63 | //Proxy all request from the root path "/" to Lambda Function One 64 | var restAPI = new LambdaRestApi(this, "Endpoint", new LambdaRestApiProps 65 | { 66 | Handler = lambdaFunctionOne, 67 | Proxy = true, 68 | }); 69 | 70 | //Proxy all request from path "/functiontwo" to Lambda Function Two 71 | var apiFunctionTwo = restAPI.Root.AddResource("functiontwo", new ResourceOptions 72 | { 73 | DefaultIntegration = new LambdaIntegration(lambdaFunctionTwo) 74 | }); 75 | apiFunctionTwo.AddMethod("ANY"); 76 | apiFunctionTwo.AddProxy(); 77 | 78 | //Proxy all request from path "/functionthree" to Lambda Function Three 79 | var apiFunctionThree = restAPI.Root.AddResource("functionthree", new ResourceOptions 80 | { 81 | DefaultIntegration = new LambdaIntegration(lambdaFunctionThree) 82 | }); 83 | apiFunctionThree.AddMethod("ANY"); 84 | apiFunctionThree.AddProxy(); 85 | 86 | _ = new CfnOutput(this, "apigwtarn", new CfnOutputProps { Value = restAPI.ArnForExecuteApi() }); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /infra/src/Infra/Program.cs: -------------------------------------------------------------------------------- 1 | using Amazon.CDK; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace Infra 7 | { 8 | sealed class Program 9 | { 10 | public static void Main(string[] args) 11 | { 12 | var app = new App(); 13 | new InfraStack(app, "InfraStack", new StackProps 14 | { 15 | // If you don't specify 'env', this stack will be environment-agnostic. 16 | // Account/Region-dependent features and context lookups will not work, 17 | // but a single synthesized template can be deployed anywhere. 18 | 19 | // Uncomment the next block to specialize this stack for the AWS Account 20 | // and Region that are implied by the current CLI configuration. 21 | /* 22 | Env = new Amazon.CDK.Environment 23 | { 24 | Account = System.Environment.GetEnvironmentVariable("CDK_DEFAULT_ACCOUNT"), 25 | Region = System.Environment.GetEnvironmentVariable("CDK_DEFAULT_REGION"), 26 | } 27 | */ 28 | 29 | // Uncomment the next block if you know exactly what Account and Region you 30 | // want to deploy the stack to. 31 | /* 32 | Env = new Amazon.CDK.Environment 33 | { 34 | Account = "123456789012", 35 | Region = "us-east-1", 36 | } 37 | */ 38 | 39 | // For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html 40 | }); 41 | app.Synth(); 42 | } 43 | } 44 | } 45 | --------------------------------------------------------------------------------