├── .editorconfig ├── .gitattributes ├── .github ├── dependabot.yml └── workflows │ ├── backend.yml │ ├── dotnet-format-daily.yml │ └── maui.yml ├── .gitignore ├── Directory.Build.props ├── Directory.Build.targets ├── LICENSE ├── LambdaTriggers.Backend ├── GenerateThumbnail.cs ├── GetThumbnail.cs ├── LambdaTriggers.Backend.csproj ├── Properties │ └── launchSettings.json ├── S3Service.cs ├── Startup.cs ├── UploadImage.cs ├── aws-lambda-tools-defaults.json └── serverless.template ├── LambdaTriggers.Common ├── Constants.cs └── LambdaTriggers.Common.csproj ├── LambdaTriggers.Mobile ├── App.cs ├── AppShell.cs ├── GlobalUsings.cs ├── LambdaTriggers.Mobile.csproj ├── MauiProgram.cs ├── Pages │ ├── Base │ │ └── BaseContentPage.cs │ └── PhotoPage.cs ├── Platforms │ ├── Android │ │ ├── AndroidManifest.xml │ │ ├── MainActivity.cs │ │ ├── MainApplication.cs │ │ └── Resources │ │ │ └── values │ │ │ └── colors.xml │ ├── MacCatalyst │ │ ├── AppDelegate.cs │ │ ├── Info.plist │ │ └── Program.cs │ ├── Windows │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── Package.appxmanifest │ │ └── app.manifest │ └── iOS │ │ ├── AppDelegate.cs │ │ ├── Info.plist │ │ └── Program.cs ├── Properties │ └── launchSettings.json ├── Resources │ ├── AppIcon │ │ ├── appicon.svg │ │ └── appiconfg.svg │ ├── Fonts │ │ ├── OpenSans-Regular.ttf │ │ └── OpenSans-Semibold.ttf │ ├── Images │ │ └── dotnet_bot.svg │ ├── Raw │ │ └── AboutAssets.txt │ ├── Splash │ │ └── splash.svg │ └── Styles │ │ ├── Colors.xaml │ │ └── Styles.xaml ├── Services │ ├── IHttpTriggerApi.cs │ └── PhotosApiService.cs └── ViewModels │ ├── Base │ └── BaseViewModel.cs │ └── PhotoViewModel.cs ├── LambdaTriggers.sln ├── README.md └── global.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # Suppress: EC112 2 | # top-most EditorConfig file 3 | root = true 4 | 5 | # Default settings: 6 | # A newline ending every file 7 | # Use 4 spaces as indentation 8 | [*] 9 | insert_final_newline = false 10 | indent_style = space 11 | indent_size = 4 12 | 13 | # Code files 14 | [*.{cs,csx,vb,vbx}] 15 | indent_style = tab 16 | indent_size = 4 17 | 18 | # Code files 19 | [*.sln] 20 | indent_size = 4 21 | 22 | # Xml project files 23 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] 24 | indent_size = 2 25 | 26 | # Xml config files 27 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] 28 | indent_size = 2 29 | 30 | # JSON files 31 | [*.json] 32 | indent_size = 2 33 | 34 | # XML files 35 | [*.xml] 36 | indent_size = 2 37 | 38 | [*.cs] 39 | 40 | # Organize usings 41 | dotnet_sort_system_directives_first = true 42 | 43 | # IDE0160: Use file scoped namespace 44 | csharp_style_namespace_declarations = file_scoped:error 45 | 46 | # CS4014: Because this call is not awaited, execution of the current method continues before the call is completed 47 | dotnet_diagnostic.CS4014.severity = error 48 | 49 | # Remove explicit default access modifiers 50 | dotnet_style_require_accessibility_modifiers = omit_if_default:error 51 | 52 | # CA1063: Implement IDisposable Correctly 53 | dotnet_diagnostic.CA1063.severity = error 54 | 55 | # CA1001: Type owns disposable field(s) but is not disposable 56 | dotnet_diagnostic.CA1001.severity = error 57 | 58 | # Pattern matching 59 | dotnet_style_object_initializer = true:suggestion 60 | dotnet_style_collection_initializer = true:suggestion 61 | dotnet_style_coalesce_expression = true:suggestion 62 | dotnet_style_null_propagation = true:suggestion 63 | dotnet_style_explicit_tuple_names = true:suggestion 64 | dotnet_style_prefer_is_null_check_over_reference_equality_method=true:suggestion 65 | 66 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion 67 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion 68 | csharp_style_inlined_variable_declaration = true:suggestion 69 | csharp_style_throw_expression = true:suggestion 70 | csharp_style_conditional_delegate_call = true:suggestions 71 | 72 | # Naming rules 73 | 74 | dotnet_diagnostic.IDE1006.severity = error 75 | 76 | ## Public Fields are kept Pascal Case 77 | dotnet_naming_symbols.public_symbols.applicable_kinds = field 78 | dotnet_naming_symbols.public_symbols.applicable_accessibilities = public, internal 79 | 80 | dotnet_naming_style.first_word_upper_case_style.capitalization = first_word_upper 81 | 82 | dotnet_naming_rule.public_members_must_be_capitalized.symbols = public_symbols 83 | dotnet_naming_rule.public_members_must_be_capitalized.style = first_word_upper_case_style 84 | dotnet_naming_rule.public_members_must_be_capitalized.severity = suggestion 85 | 86 | ## Instance fields are camelCase 87 | dotnet_naming_rule.instance_fields_should_be_camel_case.severity = error 88 | dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields 89 | dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style 90 | 91 | dotnet_naming_symbols.instance_fields.applicable_kinds = field 92 | 93 | dotnet_naming_style.instance_field_style.capitalization = camel_case 94 | dotnet_naming_style.instance_field_style.required_prefix = _ 95 | 96 | ## Static fields are camelCase 97 | dotnet_naming_rule.static_fields_should_be_camel_case.severity = error 98 | dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields 99 | dotnet_naming_rule.static_fields_should_be_camel_case.style = static_field_style 100 | 101 | dotnet_naming_symbols.static_fields.applicable_kinds = field 102 | dotnet_naming_symbols.static_fields.required_modifiers = static 103 | dotnet_naming_symbols.static_fields.applicable_accessibilities = private, protected, protected_internal, private_protected 104 | 105 | dotnet_naming_style.static_field_style.capitalization = camel_case 106 | dotnet_naming_style.static_field_style.required_prefix = _ 107 | 108 | # Modifier preferences 109 | csharp_prefer_static_local_function = true:suggestion 110 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:error 111 | 112 | # CA1822: Member does not access instance data and can be marked as static 113 | dotnet_diagnostic.CA1822.severity = suggestion 114 | 115 | # CA1050: Declare types in namespaces 116 | dotnet_diagnostic.CA1050.severity = error 117 | 118 | # CA2016: Forward the 'cancellationToken' parameter methods that take one 119 | dotnet_diagnostic.CA2016.severity = error 120 | 121 | # CA2208: Method passes parameter as the paramName argument to a ArgumentNullException constructor. Replace this argument with one of the method's parameter names. Note that the provided parameter name should have the exact casing as declared on the method. 122 | dotnet_diagnostic.CA2208.severity = error 123 | 124 | # CA1834: Use 'StringBuilder.Append(char)' instead of 'StringBuilder.Append(string)' when the input is a constant unit string 125 | dotnet_diagnostic.CA1834.severity = error 126 | 127 | # IDE0220: Add explicit cast 128 | dotnet_diagnostic.IDE0220.severity = error -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | *.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | 65 | # Force bash scripts to always use lf line endings so that if a repo is accessed 66 | # in Unix via a file share from Windows, the scripts will work. 67 | *.sh text eol=lf 68 | 69 | # Force the docs to always use lf line endings 70 | docs/**/*.xml text eol=lf -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "nuget" 9 | directory: "/" 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /.github/workflows/backend.yml: -------------------------------------------------------------------------------- 1 | name: Backend 2 | 3 | on: 4 | push: 5 | branches: 6 | - "main" 7 | pull_request: 8 | branches: 9 | - "*" 10 | 11 | jobs: 12 | Build_Backend: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v4 17 | 18 | - name: Setup .NET v8.0 19 | uses: actions/setup-dotnet@v4 20 | with: 21 | dotnet-version: '8.0.x' 22 | 23 | - name: Setup .NET v9.0 24 | uses: actions/setup-dotnet@v4 25 | with: 26 | dotnet-version: '9.0.x' 27 | 28 | - name: Build LambdaTriggers.Backend 29 | run: dotnet build LambdaTriggers.Backend/LambdaTriggers.Backend.csproj -c Release 30 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-format-daily.yml: -------------------------------------------------------------------------------- 1 | name: Daily code format check 2 | on: 3 | schedule: 4 | - cron: 0 0 * * * # Every day at midnight (UTC) 5 | jobs: 6 | dotnet-format: 7 | runs-on: windows-latest 8 | steps: 9 | - name: Install dotnet-format 10 | run: dotnet tool install -g dotnet-format 11 | 12 | - name: Checkout repo 13 | uses: actions/checkout@v2 14 | with: 15 | ref: ${{ github.head_ref }} 16 | 17 | - name: Run dotnet format 18 | id: format 19 | uses: jfversluis/dotnet-format@v1.0.5 20 | with: 21 | repo-token: ${{ secrets.GITHUB_TOKEN }} 22 | action: "fix" 23 | #only-changed-files: true # only works for PRs 24 | workspace: "/LambdaTriggers.sln" 25 | 26 | - name: Commit files 27 | if: steps.format.outputs.has-changes == 'true' 28 | run: | 29 | git config --local user.name "brminnick" 30 | git config --local user.email "13558917+brminnick@users.noreply.github.com" 31 | git commit -a -m 'Automated dotnet-format update' 32 | 33 | - name: Create Pull Request 34 | uses: peter-evans/create-pull-request@v3 35 | with: 36 | title: '[housekeeping] Automated PR to fix formatting errors' 37 | body: | 38 | Automated PR to fix formatting errors 39 | committer: brminnick <13558917+brminnick@users.noreply.github.com> 40 | author: brminnick <13558917+brminnick@users.noreply.github.com> 41 | labels: housekeeping 42 | assignees: brminnick 43 | reviewers: brminnick 44 | branch: housekeeping/fix-codeformatting 45 | 46 | # Pushing won't work to forked repos 47 | # - name: Commit files 48 | # if: steps.format.outputs.has-changes == 'true' 49 | # run: | 50 | # git config --local user.name "brminnick" 51 | # git config --local user.email "13558917+brminnick@users.noreply.github.com" 52 | # git commit -a -m 'Automated dotnet-format update 53 | # Co-authored-by: ${{ github.event.pull_request.user.login }} <${{ github.event.pull_request.user.id }}+${{ github.event.pull_request.user.login }}@users.noreply.github.com>' 54 | 55 | # - name: Push changes 56 | # if: steps.format.outputs.has-changes == 'true' 57 | # uses: ad-m/github-push-action@v0.6.0 58 | # with: 59 | # github_token: ${{ secrets.GITHUB_TOKEN }} 60 | # branch: ${{ github.event.pull_request.head.ref }} -------------------------------------------------------------------------------- /.github/workflows/maui.yml: -------------------------------------------------------------------------------- 1 | name: .NET MAUI 2 | 3 | on: 4 | push: 5 | branches: 6 | - "main" 7 | pull_request: 8 | branches: 9 | - "*" 10 | 11 | jobs: 12 | Build_Android: 13 | runs-on: macos-15 14 | 15 | steps: 16 | - uses: actions/checkout@v1 17 | 18 | - name: Setup .NET v9.0 19 | uses: actions/setup-dotnet@v4 20 | with: 21 | dotnet-version: "9.0.x" 22 | 23 | - name: Install .NET MAUI Workload 24 | run: | 25 | dotnet workload install maui 26 | 27 | - name: Restore NuGet 28 | run: | 29 | dotnet restore ./LambdaTriggers.sln 30 | 31 | - name: Build Android App 32 | run: | 33 | dotnet build ./LambdaTriggers.Mobile/LambdaTriggers.Mobile.csproj -f net9.0-android 34 | 35 | Build_iOS: 36 | runs-on: macos-15 37 | 38 | steps: 39 | - uses: actions/checkout@v1 40 | 41 | - name: Setup .NET v9.0 42 | uses: actions/setup-dotnet@v4 43 | with: 44 | dotnet-version: "9.0.x" 45 | 46 | - name: Install .NET MAUI Workload 47 | run: | 48 | dotnet workload install maui 49 | 50 | - name: Restore NuGet 51 | run: | 52 | dotnet restore ./LambdaTriggers.sln 53 | 54 | - name: Install Xcode 55 | uses: maxim-lobanov/setup-xcode@v1 56 | with: 57 | xcode-version: latest-stable 58 | 59 | - name: Build iOS App 60 | run: | 61 | dotnet build ./LambdaTriggers.Mobile/LambdaTriggers.Mobile.csproj -f net9.0-ios 62 | 63 | Build_MacCatalyst: 64 | runs-on: macos-15 65 | 66 | steps: 67 | - uses: actions/checkout@v1 68 | 69 | - name: Setup .NET v9.0 70 | uses: actions/setup-dotnet@v4 71 | with: 72 | dotnet-version: "9.0.x" 73 | 74 | - name: Install .NET MAUI Workload 75 | run: | 76 | dotnet workload install maui 77 | 78 | - name: Restore NuGet 79 | run: | 80 | dotnet restore ./LambdaTriggers.sln 81 | 82 | - name: Install Xcode 83 | uses: maxim-lobanov/setup-xcode@v1 84 | with: 85 | xcode-version: latest-stable 86 | 87 | - name: Build macOS App 88 | run: | 89 | dotnet build ./LambdaTriggers.Mobile/LambdaTriggers.Mobile.csproj -f net9.0-maccatalyst 90 | 91 | Build_Windows: 92 | runs-on: windows-latest 93 | 94 | steps: 95 | - uses: actions/checkout@v1 96 | 97 | - uses: actions/setup-java@v2 98 | with: 99 | distribution: 'microsoft' 100 | java-version: '17' 101 | 102 | - name: Setup .NET v9.0 103 | uses: actions/setup-dotnet@v4 104 | with: 105 | dotnet-version: "9.0.x" 106 | 107 | - name: Install .NET MAUI Workload 108 | run: | 109 | dotnet workload install maui 110 | 111 | - name: Restore NuGet 112 | run: | 113 | dotnet restore ./LambdaTriggers.sln 114 | 115 | - name: Build Windows App 116 | run: | 117 | dotnet build ./LambdaTriggers.Mobile/LambdaTriggers.Mobile.csproj 118 | -------------------------------------------------------------------------------- /.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 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # ignore Xamarin.Android Resource.Designer.cs files 26 | **/*.Droid/**/[Rr]esource.[Dd]esigner.cs 27 | **/*.Android/**/[Rr]esource.[Dd]esigner.cs 28 | **/Android/**/[Rr]esource.[Dd]esigner.cs 29 | **/Droid/**/[Rr]esource.[Dd]esigner.cs 30 | 31 | # Visual Studio 2015 cache/options directory 32 | .vs/ 33 | # Uncomment if you have tasks that create the project's static files in wwwroot 34 | #wwwroot/ 35 | 36 | # MSTest test Results 37 | [Tt]est[Rr]esult*/ 38 | [Bb]uild[Ll]og.* 39 | 40 | # NUNIT 41 | *.VisualState.xml 42 | TestResult.xml 43 | 44 | # Build Results of an ATL Project 45 | [Dd]ebugPS/ 46 | [Rr]eleasePS/ 47 | dlldata.c 48 | 49 | # DNX 50 | project.lock.json 51 | artifacts/ 52 | 53 | *_i.c 54 | *_p.c 55 | *_i.h 56 | *.ilk 57 | *.meta 58 | *.obj 59 | *.pch 60 | *.pdb 61 | *.pgc 62 | *.pgd 63 | *.rsp 64 | *.sbr 65 | *.tlb 66 | *.tli 67 | *.tlh 68 | *.tmp 69 | *.tmp_proj 70 | *.log 71 | *.vspscc 72 | *.vssscc 73 | .builds 74 | *.pidb 75 | *.svclog 76 | *.scc 77 | 78 | # Chutzpah Test files 79 | _Chutzpah* 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opendb 86 | *.opensdf 87 | *.sdf 88 | *.cachefile 89 | *.VC.db 90 | *.VC.VC.opendb 91 | 92 | # Visual Studio profiler 93 | *.psess 94 | *.vsp 95 | *.vspx 96 | *.sap 97 | 98 | # TFS 2012 Local Workspace 99 | $tf/ 100 | 101 | # Guidance Automation Toolkit 102 | *.gpState 103 | 104 | # ReSharper is a .NET coding add-in 105 | _ReSharper*/ 106 | *.[Rr]e[Ss]harper 107 | *.DotSettings.user 108 | 109 | # JustCode is a .NET coding add-in 110 | .JustCode 111 | 112 | # TeamCity is a build add-in 113 | _TeamCity* 114 | 115 | # DotCover is a Code Coverage Tool 116 | *.dotCover 117 | 118 | # NCrunch 119 | _NCrunch_* 120 | .*crunch*.local.xml 121 | nCrunchTemp_* 122 | 123 | # MightyMoose 124 | *.mm.* 125 | AutoTest.Net/ 126 | 127 | # Web workbench (sass) 128 | .sass-cache/ 129 | 130 | # Installshield output folder 131 | [Ee]xpress/ 132 | 133 | # DocProject is a documentation generator add-in 134 | DocProject/buildhelp/ 135 | DocProject/Help/*.HxT 136 | DocProject/Help/*.HxC 137 | DocProject/Help/*.hhc 138 | DocProject/Help/*.hhk 139 | DocProject/Help/*.hhp 140 | DocProject/Help/Html2 141 | DocProject/Help/html 142 | 143 | # Click-Once directory 144 | publish/ 145 | 146 | # Publish Web Output 147 | *.[Pp]ublish.xml 148 | *.azurePubxml 149 | # TODO: Comment the next line if you want to checkin your web deploy settings 150 | # but database connection strings (with potential passwords) will be unencrypted 151 | *.pubxml 152 | *.publishproj 153 | 154 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 155 | # checkin your Azure Web App publish settings, but sensitive information contained 156 | # in these scripts will be unencrypted 157 | PublishScripts/ 158 | 159 | # NuGet Packages 160 | *.nupkg 161 | # The packages folder can be ignored because of Package Restore 162 | **/packages/* 163 | # except build/, which is used as an MSBuild target. 164 | !**/packages/build/ 165 | # Uncomment if necessary however generally it will be regenerated when needed 166 | #!**/packages/repositories.config 167 | # NuGet v3's project.json files produces more ignoreable files 168 | *.nuget.props 169 | *.nuget.targets 170 | 171 | # Microsoft Azure Build Output 172 | csx/ 173 | *.build.csdef 174 | 175 | # Microsoft Azure Emulator 176 | ecf/ 177 | rcf/ 178 | 179 | # Windows Store app package directories and files 180 | AppPackages/ 181 | BundleArtifacts/ 182 | Package.StoreAssociation.xml 183 | _pkginfo.txt 184 | 185 | # Visual Studio cache files 186 | # files ending in .cache can be ignored 187 | *.[Cc]ache 188 | # but keep track of directories ending in .cache 189 | !*.[Cc]ache/ 190 | 191 | # Others 192 | ClientBin/ 193 | ~$* 194 | *~ 195 | *.dbmdl 196 | *.dbproj.schemaview 197 | *.pfx 198 | *.publishsettings 199 | node_modules/ 200 | orleans.codegen.cs 201 | 202 | # Since there are multiple workflows, uncomment next line to ignore bower_components 203 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 204 | #bower_components/ 205 | 206 | # RIA/Silverlight projects 207 | Generated_Code/ 208 | 209 | # Backup & report files from converting an old project file 210 | # to a newer Visual Studio version. Backup files are not needed, 211 | # because we have git ;-) 212 | _UpgradeReport_Files/ 213 | Backup*/ 214 | UpgradeLog*.XML 215 | UpgradeLog*.htm 216 | 217 | # SQL Server files 218 | *.mdf 219 | *.ldf 220 | 221 | # Business Intelligence projects 222 | *.rdl.data 223 | *.bim.layout 224 | *.bim_*.settings 225 | 226 | # Microsoft Fakes 227 | FakesAssemblies/ 228 | 229 | # GhostDoc plugin setting file 230 | *.GhostDoc.xml 231 | 232 | # Node.js Tools for Visual Studio 233 | .ntvs_analysis.dat 234 | 235 | # Visual Studio 6 build log 236 | *.plg 237 | 238 | # Visual Studio 6 workspace options file 239 | *.opt 240 | 241 | # Visual Studio LightSwitch build output 242 | **/*.HTMLClient/GeneratedArtifacts 243 | **/*.DesktopClient/GeneratedArtifacts 244 | **/*.DesktopClient/ModelManifest.xml 245 | **/*.Server/GeneratedArtifacts 246 | **/*.Server/ModelManifest.xml 247 | _Pvt_Extensions 248 | 249 | # Paket dependency manager 250 | .paket/paket.exe 251 | paket-files/ 252 | 253 | # FAKE - F# Make 254 | .fake/ 255 | 256 | # JetBrains Rider 257 | .idea/ 258 | *.sln.iml 259 | **/.DS_Store 260 | 261 | # MFractors (Xamarin productivity tool) working folder 262 | .mfractor/ 263 | 264 | # Visual Studio Code 265 | .vscode 266 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | enable 5 | preview 6 | true 7 | enable 8 | true 9 | true 10 | true 11 | false 12 | 13 | 14 | net9.0 15 | 9.0.50 16 | true 17 | true 18 | true 19 | 20 | 21 | enable 22 | all 23 | 24 | 25 | false 26 | false 27 | 28 | 64 | 65 | nullable, 66 | CS0419,CS0618,CS1570,CS1571,CS1572,CS1573,CS1574,CS1580,CS1581,CS1584,CS1587,CS1589,CS1590,CS1591,CS1592,CS1598,CS1658,CS1710,CS1711,CS1712,CS1723,CS1734, 67 | CsWinRT1028,CsWinRT1030, 68 | XC0045,XC0103, 69 | NU1900,NU1901,NU1902,NU1903,NU1904,NU1905, 70 | NUnit1001,NUnit1002,NUnit1003,NUnit1004,NUnit1005,NUnit1006,NUnit1007,NUnit1008,NUnit1009,NUnit1010,NUnit1011,NUnit1012,NUnit1013,NUnit1014,NUnit1015,NUnit1016,NUnit1017,NUnit1018,NUnit1019,NUnit1020,NUnit1021,NUnit1022,NUnit1023,NUnit1024,NUnit1025,NUnit1026,NUnit1027,NUnit1028,NUnit1029,NUnit1030,NUnit1031,NUnit1032,NUnit1033, 71 | NUnit2001,NUnit2002,NUnit2003,NUnit2004,NUnit2005,NUnit2006,NUnit2007,NUnit2008,NUnit2009,NUnit2010,NUnit2011,NUnit2012,NUnit2013,NUnit2014,NUnit2015,NUnit2016,NUnit2017,NUnit2018,NUnit2019,NUnit2020,NUnit2021,NUnit2022,NUnit2023,NUnit2024,NUnit2025,NUnit2026,NUnit2027,NUnit2028,NUnit2029,NUnit2030,NUnit2031,NUnit2032,NUnit2033,NUnit2034,NUnit2035,NUnit2036,NUnit2037,NUnit2038,NUnit2039,NUnit2040,NUnit2041,NUnit2042,NUnit2043,NUnit2044,NUnit2045,NUnit2046,NUnit2047,NUnit2048,NUnit2049,NUnit2050, 72 | NUnit3001,NUnit3002,NUnit3003,NUnit3004, 73 | NUnit4001, 74 | IL2001,IL2002,IL2003,IL2004,IL2005,IL2006,IL2007,IL2008,IL2009, 75 | IL2010,IL2011,IL2012,IL2013,IL2014,IL2015,IL2016,IL2017,IL2018,IL2019, 76 | IL2020,IL2021,IL2022,IL2023,IL2024,IL2025,IL2026,IL2027,IL2028,IL2029, 77 | IL2030,IL2031,IL2032,IL2033,IL2034,IL2035,IL2036,IL2037,IL2038,IL2039, 78 | IL2040,IL2041,IL2042,IL2043,IL2044,IL2045,IL2046,IL2047,IL2048,IL2049, 79 | IL2050,IL2051,IL2052,IL2053,IL2054,IL2055,IL2056,IL2057,IL2058,IL2059, 80 | IL2060,IL2061,IL2062,IL2063,IL2064,IL2065,IL2066,IL2067,IL2068,IL2069, 81 | IL2070,IL2071,IL2072,IL2073,IL2074,IL2075,IL2076,IL2077,IL2078,IL2079, 82 | IL2080,IL2081,IL2082,IL2083,IL2084,IL2085,IL2086,IL2087,IL2088,IL2089, 83 | IL2090,IL2091,IL2092,IL2093,IL2094,IL2095,IL2096,IL2097,IL2098,IL2099, 84 | IL2100,IL2101,IL2102,IL2103,IL2104,IL2105,IL2106,IL2107,IL2108,IL2109, 85 | IL2110,IL2111,IL2112,IL2113,IL2114,IL2115,IL2116,IL2117,IL2118,IL2119, 86 | IL2120,IL2121,IL2122, 87 | IL3050,IL3051,IL3052,IL3053,IL3054,IL3055,IL3056 88 | 89 | 90 | -------------------------------------------------------------------------------- /Directory.Build.targets: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Brandon Minnick 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LambdaTriggers.Backend/GenerateThumbnail.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using Amazon.Lambda.Core; 3 | using Amazon.Lambda.S3Events; 4 | using Amazon.S3; 5 | using LambdaTriggers.Backend.Common; 6 | using LambdaTriggers.Common; 7 | using SixLabors.ImageSharp; 8 | using SixLabors.ImageSharp.Processing; 9 | 10 | namespace LambdaTriggers.Backend; 11 | public sealed class GenerateThumbnail(IAmazonS3 s3Client, S3Service s3Service) : IDisposable 12 | { 13 | readonly IAmazonS3 _s3Client = s3Client; 14 | readonly S3Service _s3Service = s3Service; 15 | 16 | [Amazon.Lambda.Annotations.LambdaFunction] 17 | public async Task FunctionHandler(S3Event evnt, ILambdaContext context) 18 | { 19 | var s3Event = evnt.Records?[0].S3; 20 | if (s3Event is null || s3Event.Object.Key.EndsWith(Constants.ThumbnailSuffix)) 21 | return; 22 | 23 | try 24 | { 25 | using var response = await _s3Client.GetObjectAsync(s3Event.Bucket.Name, s3Event.Object.Key); 26 | if (response.HttpStatusCode is not HttpStatusCode.OK) 27 | throw new InvalidOperationException("Failed to get S3 file"); 28 | 29 | using var imageMemoryStream = new MemoryStream(); 30 | 31 | await response.ResponseStream.CopyToAsync(imageMemoryStream).ConfigureAwait(false); 32 | if (imageMemoryStream is null || imageMemoryStream.ToArray().Length < 1) 33 | throw new InvalidOperationException($"The document '{s3Event.Object.Key}' is invalid"); 34 | 35 | using var thumbnail = await CreatePNGThumbnail(imageMemoryStream).ConfigureAwait(false); 36 | 37 | var thumbnailName = _s3Service.GenerateThumbnailFilename(s3Event.Object.Key); 38 | 39 | await _s3Service.UploadContentToS3(_s3Client, s3Event.Bucket.Name, thumbnailName, thumbnail, context.Logger).ConfigureAwait(false); 40 | } 41 | catch (Exception e) 42 | { 43 | context.Logger.LogInformation($"Error creating thumbnail for {s3Event.Object.Key} from bucket {s3Event.Bucket.Name}."); 44 | context.Logger.LogInformation(e.ToString()); 45 | throw; 46 | } 47 | } 48 | 49 | static async Task CreatePNGThumbnail(Stream imageStream) 50 | { 51 | var resizeOptions = new ResizeOptions 52 | { 53 | Mode = ResizeMode.Max, 54 | Size = new(200, 200) 55 | }; 56 | 57 | imageStream.Position = 0; 58 | using var image = await Image.LoadAsync(imageStream).ConfigureAwait(false); 59 | 60 | image.Mutate(imageContext => imageContext.Resize(resizeOptions)); 61 | 62 | var outputMemoryStream = new MemoryStream(); 63 | await image.SaveAsPngAsync(outputMemoryStream).ConfigureAwait(false); 64 | 65 | return outputMemoryStream; 66 | } 67 | 68 | public void Dispose() 69 | { 70 | _s3Client.Dispose(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /LambdaTriggers.Backend/GetThumbnail.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Text.Json; 3 | using Amazon.Lambda.Annotations.APIGateway; 4 | using Amazon.Lambda.Annotations; 5 | using Amazon.Lambda.APIGatewayEvents; 6 | using Amazon.Lambda.Core; 7 | using Amazon.S3; 8 | using LambdaTriggers.Backend.Common; 9 | using LambdaTriggers.Common; 10 | 11 | namespace LambdaTriggers.HttpTriggers; 12 | 13 | public sealed class GetThumbnail(IAmazonS3 s3Client, S3Service s3Service) : IDisposable 14 | { 15 | readonly IAmazonS3 _s3Client = s3Client; 16 | readonly S3Service _s3Service = s3Service; 17 | 18 | [LambdaFunction] 19 | [HttpApi(LambdaHttpMethod.Get, "/LambdaTriggers_GetThumbnail")] 20 | public async Task GetThumbnailHandler( 21 | APIGatewayHttpApiV2ProxyRequest request, 22 | ILambdaContext context) 23 | { 24 | if (request.QueryStringParameters is null 25 | || !request.QueryStringParameters.TryGetValue(Constants.ImageFileNameQueryParameter, out var filename) 26 | || filename is null) 27 | { 28 | return new APIGatewayHttpApiV2ProxyResponse 29 | { 30 | StatusCode = (int)HttpStatusCode.BadRequest, 31 | Body = request.QueryStringParameters?.Any() is true 32 | ? $"Invalid Request. Query Parameter, \"{request.QueryStringParameters.First().Value}\", Not Supported" 33 | : $"Invalid Request. Missing Query Parameter \"{Constants.ImageFileNameQueryParameter}\"" 34 | }; 35 | } 36 | 37 | var thumbnailFileName = _s3Service.GenerateThumbnailFilename(filename); 38 | var thumbnailUrl = await _s3Service.GetFileUri(_s3Client, S3Service.BucketName, thumbnailFileName, context.Logger).ConfigureAwait(false); 39 | 40 | return thumbnailUrl switch 41 | { 42 | null => new() 43 | { 44 | StatusCode = (int)HttpStatusCode.NotFound, 45 | Body = $"Unable to retrieve Thumbnail {thumbnailFileName} from {S3Service.BucketName}" 46 | }, 47 | _ => new() 48 | { 49 | StatusCode = (int)HttpStatusCode.OK, 50 | Body = JsonSerializer.Serialize(thumbnailUrl), 51 | } 52 | }; 53 | } 54 | 55 | public void Dispose() 56 | { 57 | _s3Client.Dispose(); 58 | } 59 | } -------------------------------------------------------------------------------- /LambdaTriggers.Backend/LambdaTriggers.Backend.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Library 4 | net8.0 5 | Lambda 6 | true 7 | true 8 | 9 | 10 | true 11 | 12 | 13 | true 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /LambdaTriggers.Backend/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Mock Lambda Test Tool": { 4 | "commandName": "Executable", 5 | "commandLineArgs": "--port 5050", 6 | "workingDirectory": ".\\bin\\$(Configuration)\\net8.0", 7 | "executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-8.0.exe" 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /LambdaTriggers.Backend/S3Service.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Text.Json; 3 | using Amazon.Lambda.Core; 4 | using Amazon.S3; 5 | using Amazon.S3.Model; 6 | using LambdaTriggers.Common; 7 | 8 | namespace LambdaTriggers.Backend.Common; 9 | 10 | public class S3Service 11 | { 12 | public const string BucketName = "lambdatriggersbucket"; 13 | 14 | public async Task UploadContentToS3(IAmazonS3 s3Client, string bucket, string key, T content, ILambdaLogger logger) 15 | { 16 | var request = content switch 17 | { 18 | Stream stream => new PutObjectRequest 19 | { 20 | InputStream = stream, 21 | BucketName = bucket, 22 | Key = key 23 | }, 24 | _ => new PutObjectRequest 25 | { 26 | ContentType = "application/json", 27 | ContentBody = JsonSerializer.Serialize(content), 28 | BucketName = bucket, 29 | Key = key 30 | } 31 | }; 32 | 33 | logger.LogInformation($"Uploading object to S3..."); 34 | 35 | var putObjectResponse = await s3Client.PutObjectAsync(request).ConfigureAwait(false); 36 | var fileUrl = s3Client.GeneratePreSignedURL(bucket, key, DateTime.UtcNow.AddYears(1), null); 37 | 38 | if (putObjectResponse.HttpStatusCode is not HttpStatusCode.OK) 39 | throw new HttpRequestException($"{nameof(IAmazonS3.PutObjectAsync)} Failed: {putObjectResponse.HttpStatusCode}"); 40 | 41 | logger.LogInformation($"Upload succeeded"); 42 | logger.LogInformation($"{nameof(putObjectResponse.ETag)}: {putObjectResponse.ETag}"); 43 | 44 | return new Uri(fileUrl); 45 | } 46 | 47 | public string GenerateThumbnailFilename(in string fileName) => Path.GetFileNameWithoutExtension(fileName) + Constants.ThumbnailSuffix; 48 | 49 | public async Task GetFileUri(IAmazonS3 s3Client, string bucket, string key, ILambdaLogger lambdaLogger, DateTime? expirationDate = default) 50 | { 51 | expirationDate ??= DateTime.UtcNow.AddMinutes(1); 52 | 53 | lambdaLogger.LogInformation("Creating Presigned URL..."); 54 | 55 | 56 | var doesFileExist = await DoesFileExist(bucket, key, s3Client, lambdaLogger).ConfigureAwait(false); 57 | if (!doesFileExist) 58 | return null; 59 | 60 | var url = s3Client.GeneratePreSignedURL(bucket, key, expirationDate.Value, null); 61 | 62 | lambdaLogger.LogInformation($"Presigned URL Expiring on {expirationDate:MMMM dd, yyyy} Generated: {url}"); 63 | 64 | return new Uri(url); 65 | } 66 | 67 | static async Task DoesFileExist(string bucket, string key, IAmazonS3 s3Client, ILambdaLogger lambdaLogger) 68 | { 69 | try 70 | { 71 | var response = await s3Client.GetObjectAsync(bucket, key).ConfigureAwait(false); 72 | return response is not null; 73 | } 74 | catch (AmazonS3Exception e) 75 | { 76 | lambdaLogger.LogError(e.Message); 77 | return false; 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /LambdaTriggers.Backend/Startup.cs: -------------------------------------------------------------------------------- 1 | using Amazon.Lambda.Core; 2 | using Amazon.Lambda.Serialization.SystemTextJson; 3 | using LambdaTriggers.Backend.Common; 4 | using Microsoft.Extensions.DependencyInjection; 5 | 6 | 7 | [assembly: LambdaSerializer(typeof(DefaultLambdaJsonSerializer))] 8 | namespace LambdaTriggers.Backend; 9 | 10 | [Amazon.Lambda.Annotations.LambdaStartup] 11 | public partial class StartupBase 12 | { 13 | public virtual void ConfigureServices(IServiceCollection services) 14 | { 15 | services.AddSingleton(); 16 | services.AddAWSService(); 17 | } 18 | } -------------------------------------------------------------------------------- /LambdaTriggers.Backend/UploadImage.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using System.Text.Json; 3 | using Amazon.Lambda.Annotations.APIGateway; 4 | using Amazon.Lambda.Annotations; 5 | using Amazon.Lambda.APIGatewayEvents; 6 | using Amazon.Lambda.Core; 7 | using Amazon.S3; 8 | using HttpMultipartParser; 9 | using LambdaTriggers.Backend.Common; 10 | using LambdaTriggers.Common; 11 | 12 | namespace LambdaTriggers.Backend; 13 | 14 | public sealed class UploadImage(IAmazonS3 s3Client, S3Service s3Service) : IDisposable 15 | { 16 | readonly IAmazonS3 _s3Client = s3Client; 17 | readonly S3Service _s3Service = s3Service; 18 | 19 | [LambdaFunction] 20 | [HttpApi(LambdaHttpMethod.Post, "/LambdaTriggers_UploadImage")] 21 | public async Task UploadImageHandler( 22 | APIGatewayHttpApiV2ProxyRequest request, 23 | ILambdaContext context) 24 | { 25 | if (request.QueryStringParameters is null 26 | || !request.QueryStringParameters.TryGetValue(Constants.ImageFileNameQueryParameter, out var filename) 27 | || filename is null) 28 | { 29 | return new APIGatewayHttpApiV2ProxyResponse 30 | { 31 | StatusCode = (int)HttpStatusCode.BadRequest, 32 | Body = request.QueryStringParameters?.Any() is true 33 | ? $"Invalid Request. Query Parameter, \"{request.QueryStringParameters.First().Value}\", Not Supported" 34 | : $"Invalid Request. Missing Query Parameter \"{Constants.ImageFileNameQueryParameter}\"" 35 | }; 36 | } 37 | 38 | try 39 | { 40 | var multipartFormParser = await MultipartFormDataParser.ParseAsync(new MemoryStream(Convert.FromBase64String(request.Body))); 41 | var image = multipartFormParser.Files[0].Data; 42 | 43 | var photoUri = await _s3Service.UploadContentToS3(_s3Client, S3Service.BucketName, filename, image, context.Logger); 44 | context.Logger.LogInformation("Saved Photo to S3"); 45 | 46 | return new APIGatewayHttpApiV2ProxyResponse 47 | { 48 | StatusCode = (int)HttpStatusCode.OK, 49 | Body = JsonSerializer.Serialize(photoUri) 50 | }; 51 | } 52 | catch (Exception ex) 53 | { 54 | context.Logger.LogError(ex.Message); 55 | 56 | return new APIGatewayHttpApiV2ProxyResponse 57 | { 58 | StatusCode = (int)HttpStatusCode.InternalServerError, 59 | Body = JsonSerializer.Serialize(ex.Message) 60 | }; 61 | } 62 | } 63 | 64 | public void Dispose() 65 | { 66 | _s3Client.Dispose(); 67 | } 68 | } -------------------------------------------------------------------------------- /LambdaTriggers.Backend/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "region" : "us-west-1", 4 | "profile" : "Visual Studio Toolkit", 5 | "s3-bucket" : "lambdatriggersbucket", 6 | "template" : "serverless.template", 7 | "stack-name" : "LambdaTriggers" 8 | } -------------------------------------------------------------------------------- /LambdaTriggers.Backend/serverless.template: -------------------------------------------------------------------------------- 1 | { 2 | "AWSTemplateFormatVersion": "2010-09-09", 3 | "Transform": "AWS::Serverless-2016-10-31", 4 | "Description": "This template is partially managed by Amazon.Lambda.Annotations (v1.6.1.0).", 5 | "Resources": { 6 | "LambdaTriggersBackendGenerateThumbnailFunctionHandlerGenerated": { 7 | "Type": "AWS::Serverless::Function", 8 | "Metadata": { 9 | "Tool": "Amazon.Lambda.Annotations" 10 | }, 11 | "Properties": { 12 | "Runtime": "dotnet8", 13 | "CodeUri": ".", 14 | "MemorySize": 512, 15 | "Timeout": 30, 16 | "Role": "arn:aws:iam::723361041013:role/lambda_exec_LambdaTriggers-0", 17 | "Policies": [ 18 | "AWSLambdaBasicExecutionRole" 19 | ], 20 | "PackageType": "Zip", 21 | "Handler": "LambdaTriggers.Backend::LambdaTriggers.Backend.GenerateThumbnail_FunctionHandler_Generated::FunctionHandler" 22 | } 23 | }, 24 | "LambdaTriggersHttpTriggersGetThumbnailGetThumbnailHandlerGenerated": { 25 | "Type": "AWS::Serverless::Function", 26 | "Metadata": { 27 | "Tool": "Amazon.Lambda.Annotations", 28 | "SyncedEvents": [ 29 | "RootGet" 30 | ], 31 | "SyncedEventProperties": { 32 | "RootGet": [ 33 | "Path", 34 | "Method" 35 | ] 36 | } 37 | }, 38 | "Properties": { 39 | "Runtime": "dotnet8", 40 | "CodeUri": ".", 41 | "MemorySize": 512, 42 | "Timeout": 30, 43 | "Role": "arn:aws:iam::723361041013:role/lambda_exec_LambdaTriggers-0", 44 | "Policies": [ 45 | "AWSLambdaBasicExecutionRole" 46 | ], 47 | "PackageType": "Zip", 48 | "Handler": "LambdaTriggers.Backend::LambdaTriggers.HttpTriggers.GetThumbnail_GetThumbnailHandler_Generated::GetThumbnailHandler", 49 | "Events": { 50 | "RootGet": { 51 | "Type": "HttpApi", 52 | "Properties": { 53 | "Path": "/LambdaTriggers_GetThumbnail", 54 | "Method": "GET" 55 | } 56 | } 57 | } 58 | } 59 | }, 60 | "LambdaTriggersBackendUploadImageUploadImageHandlerGenerated": { 61 | "Type": "AWS::Serverless::Function", 62 | "Metadata": { 63 | "Tool": "Amazon.Lambda.Annotations", 64 | "SyncedEvents": [ 65 | "RootPost" 66 | ], 67 | "SyncedEventProperties": { 68 | "RootPost": [ 69 | "Path", 70 | "Method" 71 | ] 72 | } 73 | }, 74 | "Properties": { 75 | "Runtime": "dotnet8", 76 | "CodeUri": ".", 77 | "MemorySize": 512, 78 | "Timeout": 30, 79 | "Role": "arn:aws:iam::723361041013:role/lambda_exec_LambdaTriggers-0", 80 | "Policies": [ 81 | "AWSLambdaBasicExecutionRole" 82 | ], 83 | "PackageType": "Zip", 84 | "Handler": "LambdaTriggers.Backend::LambdaTriggers.Backend.UploadImage_UploadImageHandler_Generated::UploadImageHandler", 85 | "Events": { 86 | "RootPost": { 87 | "Type": "HttpApi", 88 | "Properties": { 89 | "Path": "/LambdaTriggers_UploadImage", 90 | "Method": "POST" 91 | } 92 | } 93 | } 94 | } 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /LambdaTriggers.Common/Constants.cs: -------------------------------------------------------------------------------- 1 | namespace LambdaTriggers.Common; 2 | 3 | public static class Constants 4 | { 5 | public const string ImageFileNameQueryParameter = "filename"; 6 | public const string LambdaApiUrl = "https://em34iy5v91.execute-api.us-west-1.amazonaws.com/"; 7 | public const string ThumbnailSuffix = "_thumbnail.png"; 8 | } -------------------------------------------------------------------------------- /LambdaTriggers.Common/LambdaTriggers.Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/App.cs: -------------------------------------------------------------------------------- 1 | namespace LambdaTriggers.Mobile; 2 | 3 | partial class App(AppShell shell) : Application 4 | { 5 | readonly AppShell _appShell = shell; 6 | 7 | protected override Window CreateWindow(IActivationState? activationState) => new(_appShell); 8 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/AppShell.cs: -------------------------------------------------------------------------------- 1 | namespace LambdaTriggers.Mobile; 2 | 3 | partial class AppShell : Shell 4 | { 5 | public AppShell(PhotoPage photoPage) 6 | { 7 | Items.Add(photoPage); 8 | } 9 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | global using CommunityToolkit.Mvvm.ComponentModel; 2 | global using CommunityToolkit.Mvvm.Input; -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/LambdaTriggers.Mobile.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MauiNetVersion)-android;$(MauiNetVersion)-ios;$(MauiNetVersion)-maccatalyst 5 | $(TargetFrameworks);$(MauiNetVersion)-windows10.0.19041.0 6 | Exe 7 | LambdaTriggers.Mobile 8 | true 9 | true 10 | 11 | 12 | LambdaTriggers.Mobile 13 | 14 | 15 | com.companyname.lambdatriggers.mobile 16 | cc5739ff-93ef-42c2-95e9-21d8898fcdb4 17 | 18 | 19 | 1.0 20 | 1 21 | 22 | 15.0 23 | 15.0 24 | 25.0 25 | 35.0 26 | 10.0.17763.0 27 | 10.0.17763.0 28 | 29 | 10.0.19041.41 30 | 31 | true 32 | 33 | 34 | 35 | false 36 | 37 | 38 | false 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/MauiProgram.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | using CommunityToolkit.Maui; 3 | using CommunityToolkit.Maui.Markup; 4 | using LambdaTriggers.Common; 5 | using Microsoft.Extensions.Http.Resilience; 6 | using Polly; 7 | using Refit; 8 | 9 | namespace LambdaTriggers.Mobile; 10 | 11 | public static class MauiProgram 12 | { 13 | public static MauiApp CreateMauiApp() 14 | { 15 | var builder = MauiApp.CreateBuilder() 16 | .UseMauiApp() 17 | .UseMauiCommunityToolkit() 18 | .UseMauiCommunityToolkitMarkup(); 19 | 20 | // App Shell 21 | builder.Services.AddTransient(); 22 | 23 | // Services 24 | builder.Services.AddSingleton(); 25 | builder.Services.AddSingleton(MediaPicker.Default); 26 | builder.Services.AddSingleton(); 27 | builder.Services.AddRefitClient() 28 | .ConfigureHttpClient(static client => client.BaseAddress = new Uri(Constants.LambdaApiUrl)) 29 | .AddStandardResilienceHandler(static options => options.Retry = new MobileHttpRetryStrategyOptions() ); 30 | 31 | // Pages + View Models 32 | builder.Services.AddTransient(); 33 | 34 | return builder.Build(); 35 | } 36 | 37 | sealed class MobileHttpRetryStrategyOptions : HttpRetryStrategyOptions 38 | { 39 | public MobileHttpRetryStrategyOptions() 40 | { 41 | BackoffType = DelayBackoffType.Exponential; 42 | MaxRetryAttempts = 25; 43 | UseJitter = true; 44 | Delay = TimeSpan.FromMilliseconds(200); 45 | ShouldHandle = static args => args.Outcome switch 46 | { 47 | { Exception: ApiException } => PredicateResult.True(), 48 | { Exception: HttpRequestException } => PredicateResult.True(), 49 | { Result.StatusCode: HttpStatusCode.NotFound } => PredicateResult.True(), 50 | { Result.IsSuccessStatusCode: false } => PredicateResult.True(), 51 | _ => PredicateResult.False() 52 | }; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Pages/Base/BaseContentPage.cs: -------------------------------------------------------------------------------- 1 | namespace LambdaTriggers.Mobile; 2 | 3 | abstract class BaseContentPage : ContentPage where T : BaseViewModel 4 | { 5 | protected BaseContentPage(T viewModel, string pageTitle) 6 | { 7 | base.BindingContext = viewModel; 8 | 9 | Padding = 12; 10 | Title = pageTitle; 11 | } 12 | 13 | protected new T BindingContext => (T)base.BindingContext; 14 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Pages/PhotoPage.cs: -------------------------------------------------------------------------------- 1 | using CommunityToolkit.Maui.Markup; 2 | using Microsoft.Maui.Controls.Shapes; 3 | using static CommunityToolkit.Maui.Markup.GridRowsColumns; 4 | 5 | namespace LambdaTriggers.Mobile; 6 | 7 | partial class PhotoPage : BaseContentPage 8 | { 9 | public PhotoPage(PhotoViewModel photoViewModel) : base(photoViewModel, "Photo Page") 10 | { 11 | photoViewModel.Error += HandleError; 12 | 13 | Content = new Grid 14 | { 15 | RowDefinitions = Rows.Define( 16 | (Row.Photo, Stars(5)), 17 | (Row.UploadButton, Stars(2)), 18 | (Row.ActivityIndicator, Star)), 19 | 20 | ColumnDefinitions = Columns.Define( 21 | (Column.CapturedPhoto, Star), 22 | (Column.Thumbnail, Star)), 23 | 24 | ColumnSpacing = 12, 25 | 26 | Children = 27 | { 28 | new ImageBorder 29 | { 30 | Content = new Grid 31 | { 32 | Children = 33 | { 34 | new Label() 35 | .Row(0) 36 | .Center() 37 | .Text("Captured Photo") 38 | .TextCenter(), 39 | 40 | new PhotoImage() 41 | .Row(0) 42 | .Bind(Image.SourceProperty, 43 | getter: static vm => vm.CapturedPhoto, 44 | convert: static image => image is not null ? ImageSource.FromStream(() => image) : null) 45 | } 46 | } 47 | 48 | }.Row(Row.Photo).Column(Column.CapturedPhoto), 49 | 50 | new ImageBorder 51 | { 52 | Content = new Grid 53 | { 54 | new Label() 55 | .Row(0) 56 | .Center() 57 | .Text("Thumbnail") 58 | .TextCenter(), 59 | 60 | new PhotoImage() 61 | .Row(0) 62 | .Bind( 63 | Image.SourceProperty, 64 | getter: static vm => vm.ThumbnailPhotoUri, 65 | convert: static imageUri => imageUri is not null ? ImageSource.FromUri(imageUri) : null) 66 | } 67 | }.Row(Row.Photo).Column(Column.Thumbnail), 68 | 69 | new Button() 70 | .Row(Row.UploadButton).ColumnSpan(All()) 71 | .Center() 72 | .Text("Upload Photo") 73 | .BindCommand(static (PhotoViewModel vm) => vm.UploadPhotoCommand, mode: BindingMode.OneTime), 74 | 75 | new ActivityIndicator 76 | { 77 | IsRunning = true 78 | } 79 | .Row(Row.ActivityIndicator).ColumnSpan(All()) 80 | .Center() 81 | .Bind(IsVisibleProperty, static (PhotoViewModel vm) => vm.IsCapturingAndUploadingPhoto), 82 | } 83 | }; 84 | } 85 | 86 | enum Row { Photo, UploadButton, ActivityIndicator } 87 | enum Column { CapturedPhoto, Thumbnail } 88 | 89 | async void HandleError(object? sender, string message) => await Dispatcher.DispatchAsync(() => DisplayAlert("Error", message, "OK")); 90 | 91 | sealed partial class ImageBorder : Border 92 | { 93 | public ImageBorder() 94 | { 95 | Stroke = new SolidColorBrush(Colors.Grey); 96 | StrokeShape = new RoundRectangle 97 | { 98 | CornerRadius = 12 99 | }; 100 | StrokeThickness = 2; 101 | Padding = 12; 102 | } 103 | } 104 | 105 | sealed partial class PhotoImage : Image 106 | { 107 | public PhotoImage() 108 | { 109 | Aspect = Aspect.Center; 110 | this.Bind(IsVisibleProperty, nameof(Image.Source), source: RelativeBindingSource.Self, convert: (ImageSource? source) => source is not null); 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/Android/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Content.PM; 3 | using Android.OS; 4 | 5 | namespace LambdaTriggers.Mobile; 6 | 7 | [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ScreenOrientation = ScreenOrientation.SensorLandscape, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] 8 | public class MainActivity : MauiAppCompatActivity 9 | { 10 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/Android/MainApplication.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Runtime; 3 | 4 | namespace LambdaTriggers.Mobile; 5 | 6 | [Application] 7 | public class MainApplication : MauiApplication 8 | { 9 | public MainApplication(IntPtr handle, JniHandleOwnership ownership) 10 | : base(handle, ownership) 11 | { 12 | } 13 | 14 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 15 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/Android/Resources/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #512BD4 4 | #2B0B98 5 | #2B0B98 6 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/MacCatalyst/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace LambdaTriggers.Mobile; 4 | [Register("AppDelegate")] 5 | public class AppDelegate : MauiUIApplicationDelegate 6 | { 7 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 8 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/MacCatalyst/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIDeviceFamily 6 | 7 | 1 8 | 2 9 | 10 | UIRequiredDeviceCapabilities 11 | 12 | arm64 13 | 14 | UISupportedInterfaceOrientations 15 | 16 | UIInterfaceOrientationLandscapeLeft 17 | UIInterfaceOrientationLandscapeRight 18 | 19 | UISupportedInterfaceOrientations~ipad 20 | 21 | UIInterfaceOrientationLandscapeLeft 22 | UIInterfaceOrientationLandscapeRight 23 | 24 | XSAppIconAssets 25 | Assets.xcassets/appicon.appiconset 26 | NSCameraUsageDescription 27 | This app needs access to the camera to take photos. 28 | NSMicrophoneUsageDescription 29 | This app needs access to microphone for taking videos. 30 | NSPhotoLibraryAddUsageDescription 31 | This app needs access to the photo gallery for picking photos and videos. 32 | NSPhotoLibraryUsageDescription 33 | This app needs access to photos gallery for picking photos and videos. 34 | 35 | 36 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/MacCatalyst/Program.cs: -------------------------------------------------------------------------------- 1 | using ObjCRuntime; 2 | using UIKit; 3 | 4 | namespace LambdaTriggers.Mobile; 5 | public class Program 6 | { 7 | // This is the main entry point of the application. 8 | static void Main(string[] args) 9 | { 10 | // if you want to use a different Application Delegate class from "AppDelegate" 11 | // you can specify it here. 12 | UIApplication.Main(args, null, typeof(AppDelegate)); 13 | } 14 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/Windows/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/Windows/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.UI.Xaml; 2 | 3 | // To learn more about WinUI, the WinUI project structure, 4 | // and more about our project templates, see: http://aka.ms/winui-project-info. 5 | 6 | namespace LambdaTriggers.Mobile.WinUI; 7 | /// 8 | /// Provides application-specific behavior to supplement the default Application class. 9 | /// 10 | public partial class App : MauiWinUIApplication 11 | { 12 | /// 13 | /// Initializes the singleton application object. This is the first line of authored code 14 | /// executed, and as such is the logical equivalent of main() or WinMain(). 15 | /// 16 | public App() 17 | { 18 | this.InitializeComponent(); 19 | } 20 | 21 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/Windows/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | $placeholder$ 15 | User Name 16 | $placeholder$.png 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/Windows/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | true/PM 12 | PerMonitorV2, PerMonitor 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace LambdaTriggers.Mobile; 4 | [Register("AppDelegate")] 5 | public class AppDelegate : MauiUIApplicationDelegate 6 | { 7 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 8 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LSRequiresIPhoneOS 6 | 7 | UIDeviceFamily 8 | 9 | 1 10 | 2 11 | 12 | UIRequiredDeviceCapabilities 13 | 14 | arm64 15 | 16 | UISupportedInterfaceOrientations 17 | 18 | UIInterfaceOrientationLandscapeLeft 19 | UIInterfaceOrientationLandscapeRight 20 | 21 | UISupportedInterfaceOrientations~ipad 22 | 23 | UIInterfaceOrientationLandscapeLeft 24 | UIInterfaceOrientationLandscapeRight 25 | 26 | XSAppIconAssets 27 | Assets.xcassets/appicon.appiconset 28 | NSCameraUsageDescription 29 | This app needs access to the camera to take photos. 30 | NSMicrophoneUsageDescription 31 | This app needs access to microphone for taking videos. 32 | NSPhotoLibraryAddUsageDescription 33 | This app needs access to the photo gallery for picking photos and videos. 34 | NSPhotoLibraryUsageDescription 35 | This app needs access to photos gallery for picking photos and videos. 36 | 37 | 38 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Platforms/iOS/Program.cs: -------------------------------------------------------------------------------- 1 | using ObjCRuntime; 2 | using UIKit; 3 | 4 | namespace LambdaTriggers.Mobile; 5 | public class Program 6 | { 7 | // This is the main entry point of the application. 8 | static void Main(string[] args) 9 | { 10 | // if you want to use a different Application Delegate class from "AppDelegate" 11 | // you can specify it here. 12 | UIApplication.Main(args, null, typeof(AppDelegate)); 13 | } 14 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Windows Machine": { 4 | "commandName": "MsixPackage", 5 | "nativeDebugging": false 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Resources/AppIcon/appicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Resources/AppIcon/appiconfg.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Resources/Fonts/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCodeTraveler/LambdaTriggersSample/b3fc003bd24093283f8175e494dcbc37e71ed1a8/LambdaTriggers.Mobile/Resources/Fonts/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Resources/Fonts/OpenSans-Semibold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCodeTraveler/LambdaTriggersSample/b3fc003bd24093283f8175e494dcbc37e71ed1a8/LambdaTriggers.Mobile/Resources/Fonts/OpenSans-Semibold.ttf -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Resources/Images/dotnet_bot.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Resources/Raw/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories). Deployment of the asset to your application 3 | is automatically handled by the following `MauiAsset` Build Action within your `.csproj`. 4 | 5 | 6 | 7 | These files will be deployed with you package and will be accessible using Essentials: 8 | 9 | async Task LoadMauiAsset() 10 | { 11 | using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); 12 | using var reader = new StreamReader(stream); 13 | 14 | var contents = reader.ReadToEnd(); 15 | } 16 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Resources/Splash/splash.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Resources/Styles/Colors.xaml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 6 | 7 | #512BD4 8 | #DFD8F7 9 | #2B0B98 10 | White 11 | Black 12 | #E1E1E1 13 | #C8C8C8 14 | #ACACAC 15 | #919191 16 | #6E6E6E 17 | #404040 18 | #212121 19 | #141414 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | #F7B548 35 | #FFD590 36 | #FFE5B9 37 | #28C2D1 38 | #7BDDEF 39 | #C3F2F4 40 | #3E8EED 41 | #72ACF1 42 | #A7CBF6 43 | 44 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Resources/Styles/Styles.xaml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 6 | 7 | 10 | 11 | 15 | 16 | 21 | 22 | 25 | 26 | 49 | 50 | 67 | 68 | 88 | 89 | 110 | 111 | 132 | 133 | 138 | 139 | 159 | 160 | 178 | 179 | 183 | 184 | 206 | 207 | 222 | 223 | 243 | 244 | 247 | 248 | 271 | 272 | 292 | 293 | 299 | 300 | 319 | 320 | 323 | 324 | 352 | 353 | 373 | 374 | 378 | 379 | 391 | 392 | 397 | 398 | 404 | 405 | 406 | -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Services/IHttpTriggerApi.cs: -------------------------------------------------------------------------------- 1 | using LambdaTriggers.Common; 2 | using Refit; 3 | 4 | namespace LambdaTriggers.Mobile; 5 | 6 | [Headers("Accept-Encoding: gzip", "Accept: application/json")] 7 | public interface IHttpTriggerApi 8 | { 9 | [Post($"/LambdaTriggers_UploadImage?{Constants.ImageFileNameQueryParameter}={{photoTitle}}"), Multipart] 10 | Task UploadPhoto(string photoTitle, [AliasAs("photo")] StreamPart photoStream, CancellationToken token); 11 | 12 | [Get($"/LambdaTriggers_GetThumbnail?{Constants.ImageFileNameQueryParameter}={{photoTitle}}")] 13 | Task GetThumbnailUri(string photoTitle, CancellationToken token); 14 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/Services/PhotosApiService.cs: -------------------------------------------------------------------------------- 1 | using Refit; 2 | 3 | namespace LambdaTriggers.Mobile; 4 | 5 | class PhotosApiService(IHttpTriggerApi httpTriggerApiClient) 6 | { 7 | readonly IHttpTriggerApi _httpTriggerApiClient = httpTriggerApiClient; 8 | 9 | public async Task UploadPhoto(string photoTitle, FileResult photoMediaFile, CancellationToken token) 10 | { 11 | var fileStream = await photoMediaFile.OpenReadAsync().ConfigureAwait(false); 12 | return await _httpTriggerApiClient.UploadPhoto(photoTitle, new StreamPart(fileStream, $"{photoTitle}"), token).ConfigureAwait(false); 13 | } 14 | 15 | public Task GetThumbnailUri(string photoTitle, CancellationToken token) => _httpTriggerApiClient.GetThumbnailUri(photoTitle, token); 16 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/ViewModels/Base/BaseViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace LambdaTriggers.Mobile; 2 | 3 | abstract class BaseViewModel : ObservableObject 4 | { 5 | } -------------------------------------------------------------------------------- /LambdaTriggers.Mobile/ViewModels/PhotoViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace LambdaTriggers.Mobile; 2 | 3 | partial class PhotoViewModel(IDispatcher dispatcher, IMediaPicker mediaPicker, PhotosApiService photosApiService) : BaseViewModel 4 | { 5 | readonly WeakEventManager _eventManager = new(); 6 | readonly IDispatcher _dispatcher = dispatcher; 7 | readonly IMediaPicker _mediaPicker = mediaPicker; 8 | readonly PhotosApiService _photosApiService = photosApiService; 9 | 10 | public event EventHandler Error 11 | { 12 | add => _eventManager.AddEventHandler(value); 13 | remove => _eventManager.RemoveEventHandler(value); 14 | } 15 | 16 | [ObservableProperty, NotifyCanExecuteChangedFor(nameof(UploadPhotoCommand))] 17 | public partial bool IsCapturingAndUploadingPhoto { get; private set; } 18 | 19 | [ObservableProperty] 20 | public partial Stream? CapturedPhoto { get; private set; } 21 | 22 | [ObservableProperty] 23 | public partial Uri? ThumbnailPhotoUri { get; private set; } 24 | 25 | bool CanUploadPhotoExecute => !IsCapturingAndUploadingPhoto; 26 | 27 | [RelayCommand(CanExecute = nameof(CanUploadPhotoExecute))] 28 | async Task UploadPhoto(CancellationToken token) 29 | { 30 | CapturedPhoto = null; 31 | ThumbnailPhotoUri = null; 32 | 33 | try 34 | { 35 | var storageReadPermissionResult = await _dispatcher.DispatchAsync(Permissions.RequestAsync); 36 | 37 | if (storageReadPermissionResult is not PermissionStatus.Granted) 38 | { 39 | OnError("Storage Read Permission Not Granted"); 40 | return; 41 | } 42 | 43 | var storageWritePermissionResult = await _dispatcher.DispatchAsync(Permissions.RequestAsync); 44 | 45 | if (storageWritePermissionResult is not PermissionStatus.Granted) 46 | { 47 | OnError("Storage Write Permission Not Granted"); 48 | return; 49 | } 50 | 51 | var cameraPermissionResult = await _dispatcher.DispatchAsync(Permissions.RequestAsync); 52 | 53 | if (cameraPermissionResult is not PermissionStatus.Granted) 54 | { 55 | OnError("Camera Permission Not Granted"); 56 | return; 57 | } 58 | 59 | IsCapturingAndUploadingPhoto = true; 60 | 61 | var photo = await _dispatcher.DispatchAsync(() => _mediaPicker.CapturePhotoAsync(new() 62 | { 63 | Title = Guid.NewGuid().ToString() 64 | })).ConfigureAwait(false); 65 | 66 | if (photo is null) 67 | return; 68 | 69 | ThumbnailPhotoUri = null; 70 | CapturedPhoto = await photo.OpenReadAsync().ConfigureAwait(false); 71 | 72 | await _photosApiService.UploadPhoto(photo.FileName, photo, token).ConfigureAwait(false); 73 | 74 | ThumbnailPhotoUri = await _photosApiService.GetThumbnailUri(photo.FileName, token).ConfigureAwait(false); 75 | 76 | await Task.Delay(TimeSpan.FromSeconds(2), token).ConfigureAwait(false); 77 | } 78 | catch (Exception e) 79 | { 80 | OnError(e.Message); 81 | } 82 | finally 83 | { 84 | IsCapturingAndUploadingPhoto = false; 85 | } 86 | } 87 | 88 | void OnError(in string message) => _eventManager.HandleEvent(this, message, nameof(Error)); 89 | } -------------------------------------------------------------------------------- /LambdaTriggers.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33213.308 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E89E6DF8-8F9C-4E27-ACC7-2EF951B67581}" 7 | ProjectSection(SolutionItems) = preProject 8 | .editorconfig = .editorconfig 9 | Directory.Build.props = Directory.Build.props 10 | Directory.Build.targets = Directory.Build.targets 11 | global.json = global.json 12 | EndProjectSection 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Backend", "Backend", "{5CD827CF-5A01-4CDE-BAC5-A2CD3CC6194A}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LambdaTriggers.Mobile", "LambdaTriggers.Mobile\LambdaTriggers.Mobile.csproj", "{EC4A1A6B-34F4-44F1-85C8-C95197D854E6}" 17 | EndProject 18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{31DC17FF-7664-4437-BAD4-949626A85F75}" 19 | EndProject 20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mobile", "Mobile", "{4E8C7AA8-81D4-4DF5-A8B2-E935BC6212D7}" 21 | EndProject 22 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LambdaTriggers.Common", "LambdaTriggers.Common\LambdaTriggers.Common.csproj", "{736602EF-FBDF-48AF-BF16-85C564653846}" 23 | EndProject 24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LambdaTriggers.Backend", "LambdaTriggers.Backend\LambdaTriggers.Backend.csproj", "{5AC863A6-29F1-4202-BE37-8DB8D45E8B3C}" 25 | EndProject 26 | Global 27 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 28 | Debug|Any CPU = Debug|Any CPU 29 | Release|Any CPU = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 32 | {EC4A1A6B-34F4-44F1-85C8-C95197D854E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {EC4A1A6B-34F4-44F1-85C8-C95197D854E6}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {EC4A1A6B-34F4-44F1-85C8-C95197D854E6}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 35 | {EC4A1A6B-34F4-44F1-85C8-C95197D854E6}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {EC4A1A6B-34F4-44F1-85C8-C95197D854E6}.Release|Any CPU.Build.0 = Release|Any CPU 37 | {EC4A1A6B-34F4-44F1-85C8-C95197D854E6}.Release|Any CPU.Deploy.0 = Release|Any CPU 38 | {736602EF-FBDF-48AF-BF16-85C564653846}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {736602EF-FBDF-48AF-BF16-85C564653846}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {736602EF-FBDF-48AF-BF16-85C564653846}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {736602EF-FBDF-48AF-BF16-85C564653846}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {5AC863A6-29F1-4202-BE37-8DB8D45E8B3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {5AC863A6-29F1-4202-BE37-8DB8D45E8B3C}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {5AC863A6-29F1-4202-BE37-8DB8D45E8B3C}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {5AC863A6-29F1-4202-BE37-8DB8D45E8B3C}.Release|Any CPU.Build.0 = Release|Any CPU 46 | EndGlobalSection 47 | GlobalSection(SolutionProperties) = preSolution 48 | HideSolutionNode = FALSE 49 | EndGlobalSection 50 | GlobalSection(NestedProjects) = preSolution 51 | {EC4A1A6B-34F4-44F1-85C8-C95197D854E6} = {4E8C7AA8-81D4-4DF5-A8B2-E935BC6212D7} 52 | {736602EF-FBDF-48AF-BF16-85C564653846} = {31DC17FF-7664-4437-BAD4-949626A85F75} 53 | {5AC863A6-29F1-4202-BE37-8DB8D45E8B3C} = {5CD827CF-5A01-4CDE-BAC5-A2CD3CC6194A} 54 | EndGlobalSection 55 | GlobalSection(ExtensibilityGlobals) = postSolution 56 | SolutionGuid = {6A9396FE-D752-4780-B5D8-FA52E925D40E} 57 | EndGlobalSection 58 | EndGlobal 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![.NET MAUI](https://github.com/brminnick/LambdaTriggersSample/actions/workflows/maui.yml/badge.svg)](https://github.com/brminnick/LambdaTriggersSample/actions/workflows/maui.yml) [![Backend](https://github.com/brminnick/LambdaTriggersSample/actions/workflows/backend.yml/badge.svg)](https://github.com/brminnick/LambdaTriggersSample/actions/workflows/backend.yml) 2 | # Lambda Triggers Sample 3 | 4 | A sample app demonstrating an end-to-end mobile workflow using [.NET MAUI](https://learn.microsoft.com/en-us/dotnet/maui/?view=net-maui-7.0), + [Serverless AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/lambda-csharp.html) + [AWS S3 Storage](https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/csharp_s3_code_examples.html) in C#. 5 | 6 | This sample demonstrates how to use AWS Lambda's [HTTP API Gateway Triggers](https://aws.amazon.com/blogs/developer/deploy-an-existing-asp-net-core-web-api-to-aws-lambda/) + [S3 Triggers](https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html) to automatically generate thumbnails of an uploaded image from a mobile app. 7 | 8 | 1. The .NET MAUI mobile app captures a photo 9 | 2. The .NET MAUI mobile app uploads photo to AWS via an AWS Lambda using an API Gateway HTTP trigger 10 | 3. The AWS Lambda API Gateway Function saves the image to AWS S3 Storage 11 | 4. An AWS Lambda S3 Trigger automatically generates a downscaled thumbnail of the image and saves the thumbnail image back to S3 Storage 12 | 5. The .NET MAUI mobile app retrives the thumbnail image via an AWS Lambda using an API Gateway HTTP trigger and displays it on screen 13 | 14 | ![](https://user-images.githubusercontent.com/13558917/214541434-0244c7f0-cc13-4273-89b0-af5ffd9f9786.png) 15 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "9.0.100", 4 | "rollForward": "latestFeature", 5 | "allowPrerelease": false 6 | } 7 | } --------------------------------------------------------------------------------