I am trying to use the Aspire function apps.
builder.AddAzureFunctionsProject<MyProj>("myproj");
There is a WithHostStorage() method which I would like to point at an already running docker azurite container storage account. I do not want to use the RunAsEmulator option as my storage account already has some pre configured blobs, tables etc which is managed as an external dependancy to my Aspire App Host. Think of it as a cross cutting concern if you will.
Does anyone know if it is possible to use the WithHostStorage to pass it the necessary connection string or otherwise to this -
This container is already persisted over restarts and is accessible from the storage account explorer tool. I do not want another emulator running on a different external port and mapping to an internal container port of 10000.
"AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;AccountName=devstoreaccount1;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;"
I have tried many different approaches and scoured the documentation with a fine tooth comb but I have come up short.
Can anyone please help me?
.NET Aspire Azure functions integration is currently in preview state.
Implement below provided alternatives to connect to the existing storage account instead of a new storage in .NET Aspire Azure functions.
App Host=>User Secrets=> ConnectionStrings
. The App Host injects the connection string as an application setting or environment variable into all the dependent resources:{
"ConnectionStrings": {
"blobs": "https://{account_name}.blob.core.windows.net/"
}
}
(or)
{
"StorageConnection": "<connectionstring>",
"StorageConnection:blobServiceUri": "https://{account_name}.blob.core.windows.net/",
"StorageConnection:queueServiceUri": "https://{account_name}.queue.core.windows.net/",
}
Aspirefunctionsclient:
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
builder.AddAzureQueueClient("Queues", configureSettings: null, configureClientBuilder: config =>
{
config.ConfigureOptions(configureOptions =>
{
configureOptions.MessageEncoding = QueueMessageEncoding.Base64;
});
});
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddAzureClients(clientBuilder =>
{
clientBuilder.AddBlobServiceClient(builder.Configuration["StorageConnection:blobServiceUri"]!).WithName("StorageConnection");
clientBuilder.AddQueueServiceClient(builder.Configuration["StorageConnection:queueServiceUri"]!).WithName("StorageConnection");
clientBuilder.AddTableServiceClient(builder.Configuration["StorageConnection:tableServiceUri"]!).WithName("StorageConnection");
});
var app = builder.Build();
app.MapDefaultEndpoints();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();
Explicitly Set the Connection String: Instead of using .WithHostStorage()
, configure Azure Functions project to use the Azurite connection string. Set the connection string in your local.settings.json
file or environment variables.
To achieve your requirement, add a connection string to the app host using AddConnectionString method as mentioned in MSDOC.
You can use below code snippet to connect with existing storage account.
var storage =builder.AddAzureFunctionsProject<AspireFunctionsClient>("AspireFunctions")
.WithEnvironment("AzureWebJobsStorage",
"<Your_Storage_Connection_String>");