I am creating a .NET Core Web API on Amazons AWS, Elastic Beanstalk. I am trying to add a database, but their guide to add a database does not work for .Net Core http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_NET.rds.html
It says to get the relevant information using "ConfigurationManager.AppSettings;", but this is not possible in .NET Core.
Can anybody give some inforamtion about how to get the database informations? ( "RDS_DB_NAME" "RDS_USERNAME" "RDS_PASSWORD" "RDS_HOSTNAME" )
UPDATE I tried to read on https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration But I have not resolved the problem. I still cannot seem to get the values from AWS.
It just returns whatever I set in my own appsettings.json Here is my code: MyOptions.cs
public class MyOptions
{
public MyOptions()
{
// Set default value.
}
public string RDS_HOSTNAME { get; set; }
public string RDS_PORT { get; set; }
public string RDS_DB_NAME { get; set; }
public string RDS_USERNAME { get; set; }
public string RDS_PASSWORD { get; set; }
}
StartUp.cs
public void ConfigureServices(IServiceCollection services)
{
// Register the IConfiguration instance which MyOptions binds against.
services.Configure<MyOptions>(Configuration);
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvc();
}
HomeController.cs
namespace WebApplication2.Controllers
{
[Route("")]
public class HomeController : Controller
{
private readonly MyOptions _options;
public HomeController(IOptions<MyOptions> optionsAccessor)
{
_options = optionsAccessor.Value;
}
[HttpGet]
public IActionResult Index()
{
var RDS_DB_NAME = _options.RDS_DB_NAME;
var RDS_HOSTNAME = _options.RDS_HOSTNAME;
var RDS_PASSWORD = _options.RDS_PASSWORD;
var RDS_PORT = _options.RDS_PORT;
var RDS_USERNAME = _options.RDS_USERNAME;
return Content($"RDS_DB_NAME = {RDS_DB_NAME}, RDS_HOSTNAME = {RDS_HOSTNAME}, RDS_PASSWORD = { RDS_PASSWORD}, RDS_PORT = {RDS_PORT}, RDS_USERNAME = { RDS_USERNAME}");
}
}
}