diff --git a/cdk/README.md b/cdk/README.md new file mode 100644 index 00000000..e015fe12 --- /dev/null +++ b/cdk/README.md @@ -0,0 +1,26 @@ +# Deploy AWS Lambda Power Tuning using the CDK + +Here you find various CDK projects to deploy *AWS Lambda Power Tuning* using your preferred programming language. + +Currently we support: + +- [TypeScript](typescript/README.md) +- [C#](csharp/README.md) + +You can use these projects as a standalone or reuse it within your own CDK projects. + +## Prerequisites + +- [AWS CDK Toolkit](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_install) +- [General prerequisites for CDK](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_prerequisites) + +Check also the langauge specific requirements in the respective README. + +## Useful commands + +Run these commands from the project folders: + +* `cdk bootstrap` bootstrap one or more environments +* `cdk deploy` deploy this stack to your default AWS account/region +* `cdk diff` compare deployed stack with current state +* `cdk synth` emits the synthesized CloudFormation template diff --git a/cdk/csharp/.gitignore b/cdk/csharp/.gitignore new file mode 100644 index 00000000..a4609e75 --- /dev/null +++ b/cdk/csharp/.gitignore @@ -0,0 +1,342 @@ +# CDK asset staging directory +.cdk.staging +cdk.out + +# Created by https://www.gitignore.io/api/csharp + +### Csharp ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + + +# End of https://www.gitignore.io/api/csharp \ No newline at end of file diff --git a/cdk/csharp/Cdk.sln b/cdk/csharp/Cdk.sln new file mode 100644 index 00000000..f7797402 --- /dev/null +++ b/cdk/csharp/Cdk.sln @@ -0,0 +1,48 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cdk", "src\Cdk\Cdk.csproj", "{F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheLambdaPowerTunerStackTest", "tests\Cdk.Tests\Cdk.Tests.csproj", "{C97C3EF9-2E85-4625-B512-6D43FB272F8C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Debug|x64.ActiveCfg = Debug|Any CPU + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Debug|x64.Build.0 = Debug|Any CPU + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Debug|x86.ActiveCfg = Debug|Any CPU + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Debug|x86.Build.0 = Debug|Any CPU + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Release|Any CPU.Build.0 = Release|Any CPU + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Release|x64.ActiveCfg = Release|Any CPU + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Release|x64.Build.0 = Release|Any CPU + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Release|x86.ActiveCfg = Release|Any CPU + {F90E7C82-F4CE-4CF0-8B3C-3BBEE813389A}.Release|x86.Build.0 = Release|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Debug|x64.ActiveCfg = Debug|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Debug|x64.Build.0 = Debug|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Debug|x86.ActiveCfg = Debug|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Debug|x86.Build.0 = Debug|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Release|Any CPU.Build.0 = Release|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Release|x64.ActiveCfg = Release|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Release|x64.Build.0 = Release|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Release|x86.ActiveCfg = Release|Any CPU + {C97C3EF9-2E85-4625-B512-6D43FB272F8C}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/cdk/csharp/README.md b/cdk/csharp/README.md new file mode 100644 index 00000000..ade6b987 --- /dev/null +++ b/cdk/csharp/README.md @@ -0,0 +1,22 @@ +# How to deploy AWS Lambda Power Tuning using the CDK for C# + +This CDK project deploys *AWS Lambda Power Tuning* using C#. + +You can use the project as a standalone or reuse it within your own CDK projects. + + +## CDK Prerequisites + +See [here](../README.md). + + +## Language specific prerequisites + +- [.NET 8.0 or later](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_prerequisites) +- [Requirements for CDK with C#](https://docs.aws.amazon.com/cdk/v2/guide/work-with-cdk-csharp.html#csharp-prerequisites) + +## Building, testing, and deploying the app + +* `dotnet build` compile this app +* `dotnet test` test this app +* `cdk deploy` deploy this app diff --git a/cdk/csharp/cdk.json b/cdk/csharp/cdk.json new file mode 100644 index 00000000..87130966 --- /dev/null +++ b/cdk/csharp/cdk.json @@ -0,0 +1,61 @@ +{ + "app": "dotnet build && dotnet run --project src/Cdk/Cdk.csproj", + "watch": { + "include": [ + "**" + ], + "exclude": [ + "README.md", + "cdk*.json", + "src/*/obj", + "src/*/bin", + "src/*.sln", + "src/*/GlobalSuppressions.cs", + "src/*/*.csproj" + ] + }, + "context": { + "@aws-cdk/aws-lambda:recognizeLayerVersion": true, + "@aws-cdk/core:checkSecretUsage": true, + "@aws-cdk/core:target-partitions": [ + "aws", + "aws-cn" + ], + "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, + "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, + "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true, + "@aws-cdk/aws-iam:minimizePolicies": true, + "@aws-cdk/core:validateSnapshotRemovalPolicy": true, + "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true, + "@aws-cdk/aws-s3:createDefaultLoggingPolicy": true, + "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true, + "@aws-cdk/aws-apigateway:disableCloudWatchRole": true, + "@aws-cdk/core:enablePartitionLiterals": true, + "@aws-cdk/aws-events:eventsTargetQueueSameAccount": true, + "@aws-cdk/aws-iam:standardizedServicePrincipals": true, + "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true, + "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true, + "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true, + "@aws-cdk/aws-route53-patters:useCertificate": true, + "@aws-cdk/customresources:installLatestAwsSdkDefault": false, + "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true, + "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true, + "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true, + "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true, + "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true, + "@aws-cdk/aws-redshift:columnId": true, + "@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true, + "@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true, + "@aws-cdk/aws-apigateway:requestValidatorUniqueId": true, + "@aws-cdk/aws-kms:aliasNameRef": true, + "@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true, + "@aws-cdk/core:includePrefixInUniqueNameGeneration": true, + "@aws-cdk/aws-efs:denyAnonymousAccess": true, + "@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true, + "@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true, + "@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true, + "@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true, + "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true, + "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true + } +} diff --git a/cdk/csharp/src/Cdk/Cdk.csproj b/cdk/csharp/src/Cdk/Cdk.csproj new file mode 100644 index 00000000..16e9fa62 --- /dev/null +++ b/cdk/csharp/src/Cdk/Cdk.csproj @@ -0,0 +1,25 @@ + + + + Exe + net8.0 + + Major + C# + + + + + + + + + + <_Parameter1>$(MSBuildProjectName).Tests + + + + + diff --git a/cdk/csharp/src/Cdk/GlobalSuppressions.cs b/cdk/csharp/src/Cdk/GlobalSuppressions.cs new file mode 100644 index 00000000..26233fcb --- /dev/null +++ b/cdk/csharp/src/Cdk/GlobalSuppressions.cs @@ -0,0 +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")] diff --git a/cdk/csharp/src/Cdk/Program.cs b/cdk/csharp/src/Cdk/Program.cs new file mode 100644 index 00000000..05350ac5 --- /dev/null +++ b/cdk/csharp/src/Cdk/Program.cs @@ -0,0 +1,14 @@ +using Amazon.CDK; + +namespace TheLambdaPowerTunerStack +{ + sealed class Program + { + public static void Main(string[] args) + { + var app = new App(); + new TheLambdaPowerTunerStack(app, "TheLambdaPowerTunerStack", new StackProps()); + app.Synth(); + } + } +} diff --git a/cdk/csharp/src/Cdk/TheLambdaPowerTunerStack.cs b/cdk/csharp/src/Cdk/TheLambdaPowerTunerStack.cs new file mode 100644 index 00000000..bec030d3 --- /dev/null +++ b/cdk/csharp/src/Cdk/TheLambdaPowerTunerStack.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using Amazon.CDK; +using Amazon.CDK.AWS.SAM; +using Constructs; + +namespace TheLambdaPowerTunerStack +{ + public class TheLambdaPowerTunerStack : Stack + { + internal TheLambdaPowerTunerStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) + { + var stateMachineConfiguration = new Dictionary + { + // { "lambdaResource", "*" }, + // { "PowerValues", "128,256,512,1024,1536,3008" }, + // { "visualizationURL", "https://lambda-power-tuning.show/" }, + // { "totalExecutionTimeout", "300" }, + // { "payloadS3Key", "*" }, + // { "logGroupRetentionInDays", "7" }, + // { "stateMachineNamePrefix", "powerTuningStateMachine" }, + // { "permissionsBoundary", "" }, + // { "payloadS3Bucket", "" }, + // { "layerSdkName", "" }, + // { "securityGroupIds", "" }, + // { "subnetIds", "" }, + }; + + new CfnApplication(this, "SAR", new CfnApplicationProps + { + Location = new CfnApplication.ApplicationLocationProperty { + ApplicationId = "arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning", + SemanticVersion = "4.3.4" + }, + Parameters = stateMachineConfiguration + } + ); + } + } +} \ No newline at end of file diff --git a/cdk/csharp/tests/Cdk.Tests/Cdk.Tests.csproj b/cdk/csharp/tests/Cdk.Tests/Cdk.Tests.csproj new file mode 100644 index 00000000..d86e8c6a --- /dev/null +++ b/cdk/csharp/tests/Cdk.Tests/Cdk.Tests.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + diff --git a/cdk/csharp/tests/Cdk.Tests/GlobalUsings.cs b/cdk/csharp/tests/Cdk.Tests/GlobalUsings.cs new file mode 100644 index 00000000..ab67c7ea --- /dev/null +++ b/cdk/csharp/tests/Cdk.Tests/GlobalUsings.cs @@ -0,0 +1 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file diff --git a/cdk/csharp/tests/Cdk.Tests/TheLambdaPowerTunerStackTest.cs b/cdk/csharp/tests/Cdk.Tests/TheLambdaPowerTunerStackTest.cs new file mode 100644 index 00000000..cf561b5e --- /dev/null +++ b/cdk/csharp/tests/Cdk.Tests/TheLambdaPowerTunerStackTest.cs @@ -0,0 +1,35 @@ +using Amazon.CDK; +using Amazon.CDK.Assertions; + +using ObjectDict = System.Collections.Generic.Dictionary; + +namespace TheLambdaPowerTunerStack.Tests +{ + [TestClass] + public class TheLambdaPowerTunerStackTest + { + private Template? _template; + + [TestInitialize()] + public void Startup() + { + var app = new App(); + var stack = new TheLambdaPowerTunerStack(app, "TheLambdaPowerTunerStack", new StackProps()); + _template = Template.FromStack(stack); + } + + [TestMethod] + public void TestSar() + { + _template?.HasResourceProperties("AWS::Serverless::Application", new ObjectDict + { + { "Location" , new ObjectDict + { + { "ApplicationId", "arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning" }, + } + } + } + ); + } + } +} \ No newline at end of file