How to make AWS lambda configurable per environment - c#

I wish to have aws-lambda-tools-defaults setup like it's in appsettings.json to have appsetting.Development etc..
I created multiple json files but i don't know how to know on which env is lambda called

Related

How can I access data from Variable Groups in dev ops using C#?

I am using Environment.GetEnvironmentVariable but getting null
var data = Environment.GetEnvironmentVariable("variableName");
Console.WriteLine(data);
I know I am missing something but don't know why. I want to use these variables in my code and not store them in a setting.json file
I want to use these variables in my code and not store them in a setting.json file
This is not the purpose of Azure DevOps variable groups. Do not try this approach.
Variable groups are intended to store pipeline configuration values and secrets, not application configuration. As an example of how this is an incorrect usage of variable groups, the REST APIs do not and cannot return secret values. Secret values are only available in pipelines.
You should use a real configuration store solution, such as Azure App Configuration in conjunction with Azure KeyVault.

How to add a custom JSON file into IConfiguration based on a setting?

I am working on ASP.NET Core 6.0 WebAPI and I need to get data from a CRM system (Sales Logix) using Sage SData API. We have different CRM environments (Production, Staging, Development) and I want to be able to connect (or test) any environment from my WebAPI project.
For that to work, I would like to add a configuration key (to indicate a particular CRM environment) either in appsettings.json (or launchsetting.json). For example when setting is "crmEnvironment": "Development", I want to include a custom json file, named crm-dev.json. Similarly for "crmEnvironment": "Staging", I want to include crm-staging.json.
Each custom json file ideally contains the CRM Url, Username and Password.
Please tell me how can I conditionally add json config files as mentioned above, or is there any better approach of achieving similar results, considering security in mind. Best if I could have custom config files encrypted without having to shift away from the standards, just like we did for Web.Config files by inheriting ProtectedConfigurationProvider.
My questions is similar to How can I add a custom JSON file into IConfiguration?. But since Program.cs no longer uses the Main() method, I am wondering what would be the correct way to add custom json config files.
If this may work, I use this approach.
.AddJsonFile($"Config\\appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
And I will have the Json file created for each environment. You can set the environment variable value either via IHost context or may be, simplifying your need by using Environment variable values from your respective environment.

How to override blazor client configuration with environment variables?

I have working web client, it uses "wwwroot/appsettings.json" file for its configuration.
Now I would like to override just single settings using environment variable for it (as an example, in reality there will be many, arbitrary, overrides). Is there ready to use mechanism, similar to ASP.NET Core server (all it takes is calling extension method and combining json, env. variables)?
I am not asking about multiple .json files and switching between them depending on ENVIRONMENT variable, it is completely different scenario.
So far I didn't find anything even close, so thinking about DIY approach I see an ugly path -- moving client configuration file into hosting server, adding main node in client .json file like "client", using environment variables with prefix "client", merging those data using ASP.NET server mechanism, dumping it back to file for the client usage. And hoping it will work :-).
So I followed DIY path :-) If anyone like it here are the steps:
create 3 files with empty JSON at web client wwwroot -- appsettings.json, appsettings.Development.json and Production version as well
put your entire web client config in appsettings.json at hosting server at "CLIENT" node for example
in your server Startup constructor create configuration as usual, but then fetch entire "CLIENT" section and "jsonize" it back (see: https://stackoverflow.com/a/62533775/6734314) -- convert it to string and write to $"wwwroot/appsettings.{env.EnvironmentName}.json" (where env is IWebHostEnvironment)
And that's it -- I tested it in Development mode and in Production. The only drawbacks I see are:
it looks weird :-)
when executed using VS the written file is put not relative to binary file, but relative to project -- so when you are done you have to delete newly created file (otherwise on the next run VS will complain about conflict between two static files)
You override the settings using env. variables at server side using "CLIENT" prefix, and the rest is as usual.
For the record, I am not saying this is perfect, but I didn't look for anything more than I asked in my question. What I would like to do however is to reduce the number of steps, or even better to use some already existing mechanism. I will be grateful for the improvements/tips within those areas.

Grant a docker container access to azure storage account blob container

I'd like to dynamically grant a given Docker container (or Docker image, doesn't matter) access to a specific azure storage account blob container.
Neither the blob container nor the azure container is going to be the same every time, i.e.
Grant DockerContainer1 access to AzureContainerX
Grant DockerContainer2 access to AzureContainerY
...
Is this even possible? Can I use Volume in dockerfile? Can I do this from my .net core web API app?
If so, how?
I believe you need to set up shared named volume on host, which is then filled with data from the AzureContainerX on runtime. Then all you need to do, is to share this volume into DockerContainer2 and access data from there.
Volumes are not used in the Dockerfile, instead they are set when starting the container with CMD parameters or by using compose file.
Refer for Docker documentation how to use volumes. You can set volumes are read-only.
However, I don't know how exactly you would like to set this up dynamically. You need configuration for each AzureContainerY container, that they are putting data into correct place. Also DockerContainer1 should be configured to access for data in correct paths. This might be achieved dynamically by setting up ENV values by using ARGs, but this really depends on the context here, and gets quickly very complicated.

What is the format for Lambda Function in Amazon Web Services Websocket Gateway API route setup?

I am attempting to follow this tutorial for setting up a WebSocket API using Amazon API Gatewway:
https://medium.com/#gavinlewis/getting-started-with-websockets-on-api-gateway-with-net-and-the-serverless-framework-9065f37d06e0
Like in the tutorial, my Lambda application is written in C# with classes for Connect, Disconnect, etc.
Unlike the tutorial, I am using the AWS website to set up the Gateway API. This is where I am stuck. I can't figure out how to "map" the $connect, $disconnect, echo, etc using the website UI:
I am not sure what the format of the value for the "Lambda Function" textbox. It is probably similar to this (from tutorial) but, I get a validation error when I use this value:
CsharpHandlers::App.Disconnect::FunctionHandler
So, what is the proper value I should enter to reference my lambda application, a specific class and a specific method?
Thanks.
In the Lambda Function form field you need to put the ARN of the function you want to proxy the request to.
To modify a Lambda function's default handler, open it in the AWS Management Console, and look for the Handler field under the Function code section (e.g. LambdaTest::LambdaTest.LambdaHandler::handleRequest). Even if you change it tho, you would need to stick to the signature described in the docs.

Categories

Resources