Skip to content

Commit

Permalink
Dotnet support (#20)
Browse files Browse the repository at this point in the history
* work in progress

* adding beta instrcutions

* Update dotnet-beta.md

* Update dotnet-beta.md

* Update dotnet-beta.md

* Add Rider and VS instructions (#19)

Co-authored-by: jamesuk <[email protected]>

* removing samp local .net code warnings

* [samp local] - automate launch config for .net

* [samp-local] improve .net startup and add automatic config for rider

* [samp-local] improve .net startup and add automatic config for rider

* [samp-local] - IDE support

---------

Co-authored-by: ljacobsson <[email protected]>
Co-authored-by: James Eastham <[email protected]>
Co-authored-by: jamesuk <[email protected]>
  • Loading branch information
4 people authored Aug 7, 2023
1 parent 0dfd071 commit 7fa8771
Show file tree
Hide file tree
Showing 27 changed files with 11,360 additions and 8,355 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ The `--force-restore` flag is useful if you want to restore the original Lambda
#### Debugging with VS Code
In order to debug with vscode you need to create a launch config and a shutdown task (to restore the original Lambda code in the cloud). You can set this up automatically by running `samp local --debug`

#### Supported runtimes
* NodeJs (JavaScript and TypeScript)
* .NET 6.0 (C#) - See .NEt specific documentation [here](./docs/dotnet.md)

#### How does it work?
The tool temporarily replaces your function code in the cloud with a proxy function that relays events to your local machine over AWS IoT (MQTT). The functions are automatically restored when you exit the debugging session with the values in your processed CloudFormation tempate. The tool also sets the MemorySize to 128MB and Timeout to 60 seconds to avoid timeouts during debugging as well as saving cost.

Expand Down Expand Up @@ -166,7 +170,7 @@ Options:
-h, --help display help for command
```

![Demo](images/demo-console.gif
![Demo](images/demo-console.gif)

### samp generate
Generates SAM resources, CDK code, StepFunctions ASL and Lambda functions in any language based on a query to ChatGPT. If you ask for SAM resources, it will merges them into your existing template.
Expand Down
36 changes: 36 additions & 0 deletions docs/dotnet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Local debugging for functions written in .NET

### Prerequisites:
* Function runtime should be `dotnet6`
* Function type has to be zip. Image functions are not supported.
* Has to be a SAM project. CDK might come later.
* It assumes a folder structure where the SAM template is in the root, next to the `samconfig.toml` file
* The SAM template can be in either JSON or YAML format and can be called anything with a `json`, `yml`, `yaml` or `.template` extension
* You need to have npm/node installed on your system.

### Supported IDEs
Local debugging should work in any IDE, however `samp local --debug` automates launch config for the following IDEs:
* VS Code
* JetBrains Rider
* Visual Studio

### Get started
1. Install `samp-cli`:
```bash
$ npm install -g samp-cli
```
2. cd to your .NET Lambda project root (make sure it has been deployed and that you're targeting a test environment. *Never* run this against a production environment!)
3. Run `samp local --debug` and follow the prompts. This will create/append to `launch.json` and `tasks.json` in your `.vscode` folder with the necessary launch configuration. You only need to do this once per project.
4. Run `samp local` and leave it running. (see `samp local --help` for all options)
5. Hit F5 (or start debugging via the dropdown menu)

When you're done debugging, kill the `samp local` process with Ctrl+C (⌘+C on Mac) and you functions will be restored to run in the cloud again.


### Hot reloads and .NET

Hot reloads work well with NodeJS, but the native .NEt support isn't quite there yet and it's due in .NET 7
8. After every change to your function code you need to ensure that the `./.samp-out/dotnet.csproj` file is re-compiled. You can either:
- Manually recompile using the command line `dotnet build ./samp-out/dotnet.csproj`
- Add the `dotnet.csproj` file to your solution and recompile as part of your debug process
9. Hit F5 (or start debugging from the UI)
Binary file added images/rider-dotnet-build-task-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/rider-dotnet-debug-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7fa8771

Please sign in to comment.