Skip to content

Add support for DynamoDB Local #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 22, 2025
Merged

Add support for DynamoDB Local #3

merged 9 commits into from
Jan 22, 2025

Conversation

normj
Copy link
Member

@normj normj commented Nov 11, 2024

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.

Tests and options class exposing all of the options available for DynamoDB local have been added. PR is in draft mode till I confirm the experience with the DynamoDB team.

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.

@normj normj marked this pull request as draft November 11, 2024 08:51
@davidfowl
Copy link
Contributor

davidfowl commented Nov 13, 2024

Consider using the RunAsContainer pattern we use here

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

/// <summary>
/// The container image tag. The default is latest.
/// </summary>
public string Tag { get; set; } = "latest";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you want to use latest? It'll make people's experience unstable by default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll ping the DynamoDB team to see what they are comfortable with. They don't maintain a floating stable and latest version. So the alternative is hardcoding a specific version requiring a new release of the package every time there is a new version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with the DynamoDB team and they feel strongly that they want users using latest.

@normj normj changed the base branch from main to dev November 13, 2024 21:24
@normj
Copy link
Member Author

normj commented Nov 14, 2024

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
Copy link
Contributor

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 normj force-pushed the normj/dynamodb-local branch from b1c00ca to 75b28f6 Compare November 15, 2024 18:48
@normj
Copy link
Member Author

normj commented Nov 15, 2024

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.

@normj normj force-pushed the normj/dynamodb-local branch from 75b28f6 to 5693103 Compare November 15, 2024 21:48
@normj normj marked this pull request as ready for review December 2, 2024 18:49

<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0-preview.9.24507.7" />

<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why not use $(AspireVersion) here as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed after rebasing from dev.

/// <summary>
/// If set to true DynamoDB runs in memory instead of using a database file. DynamoDB local will run faster
/// using InMemory mode but all data will be lost when the container ends and the data stored in DynamoDB
/// local can ont exceed the available memory for the container.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo in "can ont"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -0,0 +1,71 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

//using Aspire.Hosting.Testing;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove commented out statement

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file doesn't have the Amazon header

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@normj normj force-pushed the normj/dynamodb-local branch from d7e2432 to f4d835f Compare December 3, 2024 19:06
@normj normj force-pushed the normj/dynamodb-local branch from b03d3a0 to 1335ca2 Compare January 22, 2025 01:05
@normj normj merged commit 16586b3 into dev Jan 22, 2025
5 checks passed
@normj normj deleted the normj/dynamodb-local branch January 22, 2025 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants