Bulk AWS Lambda Upload from Visual Studio - c#

Using the AWS tool plugin for Visual Studio, how do you do a bulk upload of Lambda functions to AWS?
I have a project that contains two functions that define separate lambda functions. The context menu for AWS Lambda seems to only allow for publishing one function at a time. As you can imagine, that is a bit of a maintainability nightmare.
The json config file that it generates does not have any answers either as it seems to be pretty flat and only allows a single function at a time:
"region" : "us-west-2",
"configuration" : "Release",
"framework" : "netcoreapp1.0",
"function-runtime" : "dotnetcore1.0",
"function-memory-size" : 256,
"function-timeout" : 5,
"function-handler" : "LambdaSamples::LambdaSamples.SampleFunction::HelloWorld",
"function-name" : "HelloWorld",
"function-role" : "lambda_basic_execution",
"environment-variables" : ""

The Visual Studio project called "AWS Lambda Project" is designed for single Lambda functions.
So if your solution has multiple projects, and you want to deploy them all at once, you're best off doing it by script/command line.
The Readme.md file generated by the new project wizard has instructions on deploying by command line using dotnet lambda deploy-function.

I generally create an options file for each type of release that I want, like this (the new file is aws-options-live.json and has a specific name / env variables pertaining to my live environment):
And then use the following in a batch file in a Deploy folder off of the main solution folder:
echo off
cd ..\ApiGatewayLambda
dotnet lambda deploy-function -cfg aws-options-live.json
set /p asd="Hit enter to continue"
You can then get as clever as you want to with linking multiple uploads together / error checking etc.
You can still right click on the project and choose Public to AWS Lambda - it will use the aws-lambda-tools-defaults.json file to publish the function.

Related

Current solution contains incorrect configurations mapping using Premake5 with C#

I'm trying to develop an engine and I was looking for a GUI library in C# in order to build the editor for my engine. I found Avalonia but I'm having some problems setting up the whole environment.
I'm using Premake5 as build tool mixing C++ and C# but I think the problem here is not the languages mixing.
I'm getting this error when I generate my visual studio solution file. Sorry about the image, I needed to post it that way cause when I press the "Open Configuration Manager" the error is gone and exit the Configuration Manager window the compilation works as expected, quite weird.
Here's my code:
This is the premake5 script I run:
include "Dependencies.lua"
workspace "LeafEngine"
startproject "LeafEditor"
configurations { "Debug", "Release" }
platforms { "x64" }
flags { "MultiProcessorCompile" }
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.platform}"
group "Dependencies"
include "Leaf/vendor/glfw"
include "Leaf/vendor/imgui"
group ""
include "Leaf"
include "LeafEditor"
include "LeafGame"
Leaf is my C++ engine and LeafGame just a C++ test. Leaf editor is the C# project, which looks like this:
project "LeafEditor"
kind "WindowedApp"
language "C#"
clr "On"
targetdir ("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}")
objdir ("%{wks.location}/bin-obj/" .. outputdir .. "/%{prj.name}")
dotnetframework "net6.0"
nuget { "Avalonia:0.10.13", "Avalonia.Desktop:0.10.13",
"Avalonia.Diagnostics:0.10.13", "Avalonia.ReactiveUI:0.10.13",
"XamlNameReferenceGenerator:1.3.4"
}
files
{
"src/**.cs",
"src/**.xaml",
"src/**.xaml.cs",
}
links
{
"Microsoft.CodeAnalysis.CSharp.NetAnalyzers",
"Microsoft.CodeAnalysis.NetAnalyzers",
"System.Text.Json.SourceGeneration",
"Microsoft.NETCore.APP",
}
filter "system:Windows"
defines "LF_WINDOWS"
filter "system:Unix"
defines "LF_LINUX"
filter "configurations:Debug"
defines "LF_DEBUG"
runtime "Debug"
symbols "on"
filter "configurations:Release"
defines "LF_RELEASE"
runtime "Release"
optimize "full"
Another curious thing about Avalonia: as you can see I only have one available platform ("x64") for building. Well, Avalonia compiles with ("Any CPU") platform and that also breaks my whole building set up. Besides, Avalonia gets compiled with Any CPU when I load the project not when I compile the project, is that right?
Thanks in advance, this error is killling me.
I just had the same issue, both when my C# project was built with premake and with it as an external project.
The solution (granted I gave up on premake for C# so this may only apply to externalproject) is to not add architecture or any specific platform to your workspace, and instead add it to all but your C# project. I would leave a comment since this might not be the answer you're looking for, but I don't have enough reputation. Anyway, for example,
workspace "Lotus"
startproject "LotusEditor"
configurations
{
"Debug",
"Release"
}
project "CppProject"
architecture "x86_64" -- sets CppProject as x64 but not the workspace
-- more project config
externalproject "CsProject" -- no architecture/platform set for this. Might work for non externalprojects too
location "path"
uuid "insert uuid"
kind "WindowedApp"
language "C#"
Even with my project made manually not with premake, and set with target platform as x64, it still seems to want "Any CPU" as the configuration, which premake can't do.

Passing KeyVault secrets to .net core 2 xUnit/MsTest in VSTS

I have several secrets stored in Azure KeyVault. Unfortunately I cannot find a way to pass parameters to my .net Core 2.0 test run via VSTS (Visual Studio Team Services)
Documentation says that Keyvault secrets can only be supplied via VSTS variables - fair enough - but how do I actually do this? All the information I can find on web seems outdated or doesn't work.
For example - consider RunSettings file:
<RunSettings>
<TestRunParameters>
<Parameter name="webAppUrl" value="http://localhost" />
<Parameter name="webAppUserName" />
<Parameter name="webAppPassword" />
</TestRunParameters>
</RunSettings>
I tried passing values for last 2 parameters via cmd line as follow:
vsts.console MyTest.dll /Settings:vsts.runsettings -- -webAppUserName foo
vsts.console MyTest.dll /Settings:vsts.runsettings -- webAppUserName=foo
dotnet test -s vsts.runsettings -- -webAppUserName foo
dotnet test -s vsts.runsettings -- webAppUserName=foo
but this has no effect - the webAppUserName value remains null (I can see a value for webAppUrl, so I know my code is right!)
I've also tried both the VSTS "dotnet test" task as well as the "VsTest" task from my VSTS 2017 build. The VsTest provides a Override test run parameters setting - and as per the tooltip, I tried:
-webAppUserName user -webAppPassword somethingSecret
Again - no effect!
Originally I used xUnit and had exactly the same issue - i.e. coudn't figure out a way to pass parameters via VSTS - so I tried MSTest, but same issue.
Going back to my original issue of injecting KeyVault secrets
Locally via VS Studio I was able to just do the following from my test:
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, true)
...
.AddAzureKeyVault(...)
Unfortunately, when run via VSTS, the test runner just hangs (i.e. I had to stop it after several minutes) with no log output for test step if I use either
.AddAzureKeyVault(...) or .AddEnvironmentVariables()
So I tried using VSTS Variable Groups - and linking that to KeyVault. However, keyvault secrets are not accessible via environment variables (using Enviroment.GetEnvironmentVariable(...) directly from C#) - so that's no good. They say you can only pass these to tasks via VSTS variables...hence my problem!
Aside:
Even if I could use environment variables, it's not optimal because when using .AddAzureKeyVault() I can supply a custom IKeyVaultSecretManager to, for example, replace a special delimiter with the ':' character - this means that I can nest my json config values - e.g. if I had this in my config file:
{ "A" : { "B" : "somevalue" } }
then using normal configuration builder I can access the above via config["A:B"]. Unfortunately KeyVault doesn't like the ":" character - so you have to replace it with something like "--" and then use a custom IKeyVaultSecretManager to replace "--" with ":" (which works great and ensures that variables are properly overridden based on the order of providers registered in config builder)
Please help! All I wanted for Christmas was not to put my KeyVault secrets into Git... but the VSTS KeyVault grinch is spoiling my fun... surely I'm missing something??
Just an update
I've recently set up a new xUnit .NET Core 2.0 project. For this project I had no issues passing environment variables to Azure DevOps. Basically, all you do is:
Create a Build pipeline variable - e.g. ASPNETCORE_ENVIRONMENT
Create Visual Studio Test Task
In your xUnit project, simply use System.Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")
Given that the above works, .AddEnvironmentVariables() configuration method should just work fine now aswell.
This mechanism can be used to load a different config files per test environments too.
For me, this is all I needed as I have a nice easy way to pass environment-specific options to integration tests
The format of overriding test run parameters is like AppURL=$(DeployURL);Port=8080 instead of -name value
Supplying Run Time Parameters to Tests

Storing a sqllite database in a location that visual studio and dotnet can see it

So I have a solution with two projects (webapi, console app) in it. I created a shared directory between them to put a sqlite database.
So I use
Path.GetFullPath(#"../shared/" + Configuration["DBName"]);
and get this path when i run it in visual studio 2017
\shared\sqlite.db
However when I try to run the console command
dotnet ef database update
it thinks it's located here
\projecta\bin\Debug\shared\
How can I get the Visual Studio debug and dotnet ef commands to use the same path?
When you call Path.GetFullPath, it uses the value of Directory.GetCurrentDirectory, which may vary based on who called your code (VS, dotnet, etc)
A better way to do this is give your SQLite file path a consistent location that won't vary based on the caller:
var dbPath = Path.Combine(System.AppContext.BaseDirectory, "..", "shared", Configuration["DBName"]);

VSTS build fails with MSB4184 The path is not of a legal form

I'm attempting to use the build system in VSTS to build and deploy a c# .net web app. I've created a new single-project solution (as there doesn't seem to be any way to specify which project to build/deploy in a multi project solution!?!) and set up my build definition to point to this new solution. I've set it up to use the VS2017 build agent.
The NuGet restore completes and it begins to build but fails with the error:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeployPackage.targets(124,7): Error MSB4184: The expression "[System.IO.Path]::GetDirectoryName('')" cannot be evaluated. The path is not of a legal form.
Has anyone encountered this and knows how to fix it?
Thanks
I know this might be bit late, but if it helps anyone then they should install the extension VSColorOutput
Then go to Tools => Options => VSColorOutput => General => Set Stop Build on First Error to true.
Using .Net Core step/task instead. (Command: publish; Arguments: --configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory))
Similar issue: VSTS fails to build my really really simple ASP.NET Core app

How Can I run EntityFramework Reverse POCO Code First Generator (T4) programmatically?

I want to use "EntityFramework Reverse POCO Code First Generator" but programmatically not from VS.
EntityFramework Reverse POCO Code Github
In fact I want to Run T4 for this purpose from C# code
I downloaded simple-t4-engine for this purpose
Simple T4 Engine
I wrote some code like this :
Engine engine = new Engine();
TemplatingHost host = new TemplatingHost(System.Text.Encoding.UTF32);
host.IncludeFileSearchPaths.Add(#"D:\IncludeFiles");
string templateFileName = "some template";
// NOTE: Doesn't actually seem to care about the name of the template file? True, but does use the path to search for stuff.
host.TemplateFile = templateFileName;
string input = File.ReadAllText(#"D:\IncludeFiles\T4Files\Database.tt");
string output = engine.ProcessTemplate(input, host);
File.WriteAllText(#"D:\IncludeFiles\T4Files\Output.txt", output);
StringBuilder sb = new StringBuilder();
foreach (CompilerError error in host.Errors)
{
sb.AppendLine(error.ToString());
}
File.WriteAllText(#"D:\IncludeFiles\T4Files\ErrorLog.txt", sb.ToString());
But I got some errors (Output.txt is Empty)
ErrorLog.txt :
error : Running transformation: System.InvalidCastException: Unable to cast transparent proxy to type 'System.IServiceProvider'.
at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.GetDTE()
at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.GetCurrentProject()
at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.GetConfigPaths()
at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.GetConnectionString(String& connectionStringName, String& providerName, String& configFilePath)
at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.InitConnectionString()
at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.GetDbProviderFactory()
at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.TransformText()
Can anyone help me for solve this problem ?
or introduce a better way for run Database.tt in runtime an execute in C# programmatically.
Database.tt
EF.Reverse.POCO.Core.ttinclude
EF.Reverse.POCO.ttinclude
EF.Utility.CS.ttinclude
EF6.Utility.CS.ttinclude
GenerateTSQL.Utility.ttinclude
I am the author of the Entity Framework Reverse POCO Generator.
Unfortunately, you can't run this outside of Visual Studio because the code depends on it. The EnvDTE provides the ability for the reverse generator to add/remove generated files from the Visual Studio project. Without this, it will not be able to do it's job.
Others have asked if they can run it on the build server. However the build server may not have access to the database it needs to reverse engineer. So always generate the code by saving the tt settings file, and commit the generated code to source control, and from there on to your build server.
By the way, just to be clear: I don't want this project to be automated outside of Visual Studio, or to be included in another product of any kind. This is stipulated in the license.
You can use TextTransform Utility to transform T4 files outside Visual Studio. Normally you can find util in folder:
\Program Files\Common Files\Microsoft Shared\TextTemplating\
I think this is a start for your problem please research more about this tool and check if fit your issue.

Categories