aws / integrations-on-dotnet-aspire-for-aws

This repositry contains the integrations with .NET Aspire for AWS.
MIT No Attribution
27 stars 4 forks source link

Add support for DynamoDB Local #3

Open normj opened 1 week ago

normj commented 1 week ago

Description of changes: Adds a new AddAWSDynamoDBLocal extension method for adding the DynamoDB Local container image to the Aspire application. When the DynamoDB Local Aspire resource is added as a reference to projects the AWS_ENDPOINT_URL_DYNAMODB environment variable is set. DynamoDB service clients created in the application that rely on the SDK to resolve the region/endpoint will pick up the environment variable. The AWS_ENDPOINT_URL_DYNAMODB will take precedence over the AWS_REGION environment variable.

PR is still in draft mode while investigate what other options besides DisableDynamoDBLocalTelemetry should be added and I need to add tests. For now you can see the PR in action by looking at the playground application.

Sample of what the user experience is like.

// Add a DynamoDB Local instance
var localDynamoDB = builder.AddAWSDynamoDBLocal("DynamoDBLocal");

// Reference DynamoDB local in project
builder.AddProject<Projects.Frontend>("Frontend")
        .WithReference(localDynamoDB);

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

davidfowl commented 1 week ago

Consider using the RunAsContainer pattern we use here

var redis = builder.AddAzureRedis("redis").RunAsContainer();
normj commented 1 week ago

Consider using the RunAsContainer pattern we use here

var redis = builder.AddAzureRedis("redis").RunAsContainer();

My Azure ignorance here but what does AddAzureRedis("redis") do without the the RunAsContainer()? I assume that would be an indication when doing deployment that an Azure redis should be provisioned. In this case you would never provision the service DynamoDB.

eerhardt commented 1 week ago

what does AddAzureRedis("redis") do without the the RunAsContainer()? I assume that would be an indication when doing deployment that an Azure redis should be provisioned.

If you just call .AddAzureRedis("redis"), it will provision an Azure Cache for Redis both at F5 time and during publish. When you call .AddAzureRedis("redis").RunAsContainer(), it will use the local container during F5 time and it will provision an Azure Redis service during publish.

In this case you would never provision the service DynamoDB.

Not even at publish time? What happens then?

normj commented 1 week ago

In this case you would never provision the service DynamoDB.

Not even at publish time? What happens then?

Within DynamoDB you would provision tables but you don't provision the service. And the tables would be provision via the CloudFormation integration. This is all about setting up the emulator and redirecting the SDK when attempting to access the DynamoDB service go to the local emulator.

There is a user experience question on how to create the tables within DynamoDB local because CloudFormation isn't going to do anything with the local emulator. So table creation for DynamoDB local would be done differently then when using the real service. Right now I would do it with adding a "Data Loader" project to the Aspire resource that took care of making sure DynamoDB local had all the table creation and data seeding. What I also want to experiment with is extending the AddAWSDynamoDBLocal with some fluent methods to define the local emulation tables.