![]() |
VOOZH | about |
dotnet add package Aspire.Hosting.AWS --version 13.3.0
NuGet\Install-Package Aspire.Hosting.AWS -Version 13.3.0
<PackageReference Include="Aspire.Hosting.AWS" Version="13.3.0" />
<PackageVersion Include="Aspire.Hosting.AWS" Version="13.3.0" />Directory.Packages.props
<PackageReference Include="Aspire.Hosting.AWS" />Project file
paket add Aspire.Hosting.AWS --version 13.3.0
#r "nuget: Aspire.Hosting.AWS, 13.3.0"
#:package Aspire.Hosting.AWS@13.3.0
#addin nuget:?package=Aspire.Hosting.AWS&version=13.3.0Install as a Cake Addin
#tool nuget:?package=Aspire.Hosting.AWS&version=13.3.0Install as a Cake Tool
Provides extension methods and resources definition for a .NET Aspire AppHost to configure the AWS SDK for .NET and AWS application resources.
In your AppHost project, install the Aspire.Hosting.AWS library with NuGet:
dotnet add package Aspire.Hosting.AWS
The AWS profile and region the SDK should use can be configured using the AddAWSSDKConfig method.
The following example creates a config using the dev profile from the ~/.aws/credentials file and points the SDK to the
us-west-2 region.
var awsConfig = builder.AddAWSSDKConfig()
.WithProfile("dev")
.WithRegion(RegionEndpoint.USWest2);
The configuration can be attached to projects using the WithReference method. This will set the AWS_PROFILE and AWS_REGION
environment variables on the project to the profile and region configured by the AddAWSSDKConfig method. SDK service clients created in the
project without explicitly setting the credentials and region will pick up these environment variables and use them
to configure the service client.
builder.AddProject<Projects.Frontend>("Frontend")
.WithReference(awsConfig)
If a project has a reference to an AWS resource like the AWS CloudFormation resources that have an AWS SDK configuration
the project will infer the AWS SDK configuration from the AWS resource. For example if you call the WithReference passing
in the CloudFormation resource then a second WithReference call passing in the AWS SDK configuration is not necessary.
AWS application resources like Amazon DynamoDB tables or Amazon Simple Queue Service (SQS) queues can be provisioned during AppHost startup using a CloudFormation template.
In the AppHost project create either a JSON or YAML CloudFormation template. Here is an example template called app-resources.template that creates a queue and topic.
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Parameters" : {
"DefaultVisibilityTimeout" : {
"Type" : "Number",
"Description" : "The default visibility timeout for messages in SQS queue."
}
},
"Resources" : {
"ChatMessagesQueue" : {
"Type" : "AWS::SQS::Queue",
"Properties" : {
"VisibilityTimeout" : { "Ref" : "DefaultVisibilityTimeout" }
}
},
"ChatTopic" : {
"Type" : "AWS::SNS::Topic",
"Properties" : {
"Subscription" : [
{ "Protocol" : "sqs", "Endpoint" : { "Fn::GetAtt" : [ "ChatMessagesQueue", "Arn" ] } }
]
}
}
},
"Outputs" : {
"ChatMessagesQueueUrl" : {
"Value" : { "Ref" : "ChatMessagesQueue" }
},
"ChatTopicArn" : {
"Value" : { "Ref" : "ChatTopic" }
}
}
}
In the AppHost the AddAWSCloudFormationTemplate method is used to register the CloudFormation resource. The first parameter,
which is the Aspire resource name, is used as the CloudFormation stack name when the stackName parameter is not set.
If the template defines parameters the value can be provided using
the WithParameter method. To configure what AWS account and region to deploy the CloudFormation stack,
the WithReference method is used to associate a SDK configuration.
var awsResources = builder.AddAWSCloudFormationTemplate("AspireSampleDevResources", "app-resources.template")
.WithParameter("DefaultVisibilityTimeout", "30")
.WithReference(awsConfig);
You can also add custom tags to the CloudFormation stack using the WithTag method:
var awsResources = builder.AddAWSCloudFormationTemplate("AspireSampleDevResources", "app-resources.template")
.WithParameter("DefaultVisibilityTimeout", "30")
.WithReference(awsConfig)
.WithTag("Environment", "Development")
.WithTag("Project", "AspireSample")
.WithTag("Owner", "DotNetTeam");
The outputs of a CloudFormation stack can be associated to a project using the WithReference method.
builder.AddProject<Projects.Frontend>("Frontend")
.WithReference(awsResources);
The output parameters from the CloudFormation stack can be found in the IConfiguration under the AWS:Resources config section. The config section
can be changed by setting the configSection parameter of the WithReference method associating the CloudFormation stack to the project.
var chatTopicArn = builder.Configuration["AWS:Resources:ChatTopicArn"];
Alternatively a single CloudFormation stack output parameter can be assigned to an environment variable using the GetOutput method.
builder.AddProject<Projects.Frontend>("Frontend")
.WithEnvironment("ChatTopicArnEnv", awsResources.GetOutput("ChatTopicArn"))
To import AWS resources that were created by a CloudFormation stack outside the AppHost the AddAWSCloudFormationStack method can be used.
It will associate the outputs of the CloudFormation stack the same as the provisioning method AddAWSCloudFormationTemplate.
var awsResources = builder.AddAWSCloudFormationStack("ExistingStackName")
.WithReference(awsConfig);
builder.AddProject<Projects.Frontend>("Frontend")
.WithReference(awsResources);
Adding AWS CDK to the AppHost makes it possible to provision AWS resources using code. Under the hood AWS CDK is using CloudFormation to create the resources in AWS.
In the AppHost the AddAWSCDK methods is used to create a CDK Resources which will hold the constructs for describing the AWS resources.
A number of methods are available to add common resources to the AppHost like S3 Buckets, DynamoDB Tables, SQS Queues, SNS Topics, Kinesis Streams and Cognito User Pools. These resources can be added either the CDK resource or a dedicated stack that can be created.
var stack = builder.AddAWSCDKStack("Stack");
var bucket = stack.AddS3Bucket("Bucket");
builder.AddProject<Projects.Frontend>("Frontend")
.WithReference(bucket);
Resources created with these methods can be directly referenced by project resources and common properties like resource names, ARNs or URLs will be made available as configuration environment variables. The default config section will be AWS:Resources
Alternative constructs can be created in free form using the AddConstruct methods. These constructs can be references with the WithReference method and need to be provided with a property selector and an output name. This will make this property available as configuration environment variable
var stack = builder.AddAWSCDKStack("Stack");
var constuct = stack.AddConstruct("Construct", scope => new CustomConstruct(scope, "Construct"));
builder.AddProject<Projects.Frontend>("Frontend")
.WithReference(construct, c => c.Url, "Url");
You can develop and test AWS Lambda functions locally within your .NET Aspire application. This enables testing Lambda functions alongside other application resources during development.
To add a Lambda function to your .NET Aspire AppHost, use the AddAWSLambdaFunction method. The method supports both executable Lambda functions and class library Lambda functions:
var awsConfig = builder.AddAWSSDKConfig()
.WithProfile("default")
.WithRegion(RegionEndpoint.USWest2);
// Add an executable Lambda function
builder.AddAWSLambdaFunction<Projects.ExecutableLambdaFunction>(
"MyLambdaFunction",
lambdaHandler: "ExecutableLambdaFunction")
.WithReference(awsConfig);
// Add a class library Lambda function
builder.AddAWSLambdaFunction<Projects.ClassLibraryLambdaFunction>(
"MyLambdaFunction",
lambdaHandler: "ClassLibraryLambdaFunction::ClassLibraryLambdaFunction.Function::FunctionHandler")
.WithReference(awsConfig);
The lambdaHandler parameter specifies the Lambda handler in different formats depending on the project type:
{assembly}::{type}::{method}.When adding Lambda functions to your .NET Aspire application, the integration automatically manages the installation and updates of the Amazon.Lambda.TestTool. This tool is needed for local Lambda function emulation.
You can customize the tool installation behavior by calling AddAWSLambdaServiceEmulator before any AddAWSLambdaFunction calls:
builder.AddAWSLambdaServiceEmulator(new LambdaEmulatorOptions
{
DisableAutoInstall = false,
OverrideMinimumInstallVersion = "0.1.0",
AllowDowngrade = false
});
// Add Lambda functions after configuring the emulator
var function = builder.AddAWSLambdaFunction<Projects.MyFunction>("MyFunction", "MyFunction");
The LambdaEmulatorOptions provide the following customization:
DisableAutoInstall: When set to true, it prevents the automatic installation or update of the Lambda Test Tool.OverrideMinimumInstallVersion: Allows you to specify a minimum version of the Lambda Test Tool to be installed. If a newer version is already installed, it will be used unless AllowDowngrade is set to true.AllowDowngrade: If set to true, it permits downgrading to an older version of the Lambda Test Tool when the specified version is older than the currently installed version.To add an API Gateaway emulator to your .NET Aspire AppHost, use the AddAWSAPIGatewayEmulator method.
// Add Lambda functions
var rootWebFunction = builder.AddAWSLambdaFunction<Projects.WebApiLambdaFunction>(
"RootLambdaFunction",
lambdaHandler: "WebApiLambdaFunction");
var addFunction = builder.AddAWSLambdaFunction<Projects.WebAddLambdaFunction>(
"AddLambdaFunction",
lambdaHandler: "WebAddLambdaFunction");
// Configure API Gateway emulator
builder.AddAWSAPIGatewayEmulator("APIGatewayEmulator", APIGatewayType.HttpV2)
.WithReference(rootWebFunction, Method.Get, "/")
.WithReference(addFunction, Method.Get, "/add/{x}/{y}");
The AddAWSAPIGatewayEmulator method requires:
Rest, HttpV1, or HttpV2 )Use the WithReference method to connect Lambda functions to HTTP routes, specifying:
The API Gateway emulator supports the use of wildcard path. To define a wildcard path, you can use the {proxy+} syntax in the route pattern.
Here's an example of how to set up an API Gateway emulator with a wildcard path:
// Add an ASP.NET Core Lambda function
var aspNetCoreLambdaFunction = builder.AddAWSLambdaFunction<Projects.AWSServerless>("Resource", "AWSServerless");
// Configure the API Gateway emulator
builder.AddAWSAPIGatewayEmulator("APIGatewayEmulator", APIGatewayType.Rest)
.WithReference(aspNetCoreLambdaFunction, Method.Any, "/")
.WithReference(aspNetCoreLambdaFunction, Method.Any, "/{proxy+}");
In this example, the first WithReference call maps the root path (/) to the ASP.NET Core Lambda function. The second WithReference call maps the wildcard path (/{proxy+}) to the same Lambda function.
The {proxy+} syntax captures the entire remaining part of the URL path and passes it as a parameter to the Lambda function.
By combining the ASP.NET Core bridge library and the API Gateway emulator with wildcard paths, you can easily develop and test your serverless ASP.NET Core applications locally, providing a seamless experience between local development and deployment to AWS Lambda.
Note: This feature is currently in preview and subject to change based on feedback. We encourage you to try it out and share your feedback!
The AWS deployment feature for .NET Aspire enables you to deploy your Aspire applications directly to AWS. The deployment system transforms your Aspire AppHost resources into AWS CDK constructs, which are then synthesized into CloudFormation templates and deployed to your AWS account. This provides a seamless path from local development to cloud deployment.
For comprehensive documentation including advanced scenarios, implementation details, and architectural guidance, see the .
Before deploying to AWS, ensure you have:
npm install -g aws-cdkcdk bootstrap aws://ACCOUNT-NUMBER/REGIONThe deployment system leverages AWS CDK to transform your Aspire resources into cloud infrastructure, which requires Node.js and the CDK CLI to be available in your environment.
Add an AWS CDK environment to your AppHost to enable deployment:
// Add to opt-in to using the preview publish/deployment APIs.
#pragma warning disable ASPIREAWSPUBLISHERS001
var builder = DistributedApplication.CreateBuilder(args);
// Add AWS CDK environment
builder.AddAWSCDKEnvironment(
name: "MyApp",
cdkDefaultsProviderFactory: CDKDefaultsProviderFactory.Preview_V1
);
// Add your resources
var webApp = builder.AddProject<Projects.WebApp>("webapp");
builder.Build().Run();
The name parameter identifies your application stack in AWS, and the cdkDefaultsProviderFactory parameter specifies which version of default behaviors to use (currently Preview_V1 for the preview release).
Deploying Your Application:
To deploy your application to AWS, use the Aspire CLI:
aspire publish - Transforms your Aspire resources into AWS CDK constructs and synthesizes them into a cdk.out directory containing CloudFormation templatesaspire deploy - Runs the publish step and then uses the AWS CDK CLI to deploy the cdk.out directory to your AWS accountThe deployment process will prompt you for AWS credentials and region if not already configured.
By default, Aspire resources are automatically mapped to appropriate AWS services based on their type:
// Add to opt-in to using the preview publish/deployment APIs.
#pragma warning disable ASPIREAWSPUBLISHERS001
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAWSCDKEnvironment(
name: "MyApp",
cdkDefaultsProviderFactory: CDKDefaultsProviderFactory.Preview_V1
);
// Web projects automatically deploy to ECS Fargate Express
var webApp = builder.AddProject<Projects.WebApp>("webapp");
// Lambda functions automatically deploy to AWS Lambda
var function = builder.AddAWSLambdaFunction<Projects.MyFunction>("function", "<lambda-function-handler>");
// Redis automatically deploys to ElastiCache
var cache = builder.AddRedis("cache");
builder.Build().Run();
The deployment system analyzes each resource and selects the most appropriate AWS service automatically. You don't need to specify deployment targets unless you want to customize the defaults.
You can override the default deployment target for any resource using Publish extension methods:
// Add to opt-in to using the preview publish/deployment APIs.
#pragma warning disable ASPIREAWSPUBLISHERS001
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAWSCDKEnvironment(
name: "MyApp",
cdkDefaultsProviderFactory: CDKDefaultsProviderFactory.Preview_V1
);
// Deploy web app with Application Load Balancer instead of default Express service
var webApp = builder.AddProject<Projects.WebApp>("webapp")
.PublishAsECSFargateServiceWithALB();
builder.Build().Run();
Each Publish method allows you to customize the AWS service configuration through callbacks that modify CDK construct properties. See the for details on available Publish methods and customization options.
Use WithReference() to connect resources - the deployment system automatically configures all necessary connectivity:
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAWSCDKEnvironment(
name: "MyApp",
cdkDefaultsProviderFactory: CDKDefaultsProviderFactory.Preview_V1
);
var cache = builder.AddRedis("cache");
// Connect the web app to the cache
var webApp = builder.AddProject<Projects.WebApp>("webapp")
.WithReference(cache);
builder.Build().Run();
When resources are connected with WithReference(), the system automatically:
Your application code can access the referenced resource using the standard .NET Aspire configuration patterns - no AWS-specific code required.
For advanced deployment scenarios and comprehensive implementation details, see the . The design document covers:
The design document provides detailed examples and implementation guidance for these advanced use cases, enabling you to customize deployments for production workloads.
Amazon DynamoDB provides a local version of DynamoDB for development and testing that is distributed as a container. With version 9.1.0 of the Aspire.Hosting.AWS package, you can easily integrate the DynamoDB local container with your .NET Aspire project. This enables seamless transition between DynamoDB Local for development and the production DynamoDB service in AWS, without requiring any code changes in your application.
To get started in the .NET Aspire AppHost, call the AddAWSDynamoDBLocal method to add DynamoDB local as a resource to the .NET Aspire application.
var builder = DistributedApplication.CreateBuilder(args);
// Add a DynamoDB Local instance
var localDynamoDB = builder.AddAWSDynamoDBLocal("DynamoDBLocal");
For each .NET project in the .NET Aspire application using DynamoDB, add a reference to the DynamoDB local resource.
// Reference DynamoDB local in project
builder.AddProject<Projects.Frontend>("Frontend")
.WithReference(localDynamoDB);
In the .NET projects that use DynamoDB, you need to construct the DynamoDB service client from the SDK without explicitly setting the AWS Region or service endpoint. This means constructing the AmazonDynamoDBClient object without passing in the Region or an AmazonDynamoDBConfig with the RegionEndpoint property set. By not explicitly setting the Region, the SDK searches the environment for configuration that informs the SDK where to send the requests. The Region is set locally by the AWS_REGION environment variable or in your credentials profile by setting the region property. Once deployed to AWS, the compute environments set environment configuration such as the AWS_REGION environment variable so that the SDK knows what Region to use for the service client.
The AWS SDKs have a feature called Service-specific endpoints that allow setting an endpoint for a service via an environment variable. The WithReference call made on the .NET project sets the AWS_ENDPOINT_URL_DYNAMODB environment variable. It will be set to the DynamoDB local container that was started as part of the AddAWSDynamoDBLocal method.
The AWS_ENDPOINT_URL_DYNAMODB environment variable overrides other config settings like the AWS_REGION environment variable, ensuring your projects running locally use DynamoDB local. After the AmazonDynamoDBClient has been created pointing to DynamoDB local, all other service calls work the same as if you are going to the real DynamoDB service. No code changes are required.
When the AddAWSDynamoDBLocal method is called, any data and table definitions are stored in memory by default. This means that every time the .NET Aspire application is started, DynamoDB local is initiated with a fresh instance with no tables or data. The AddAWSDynamoDBLocal method takes in an optional DynamoDBLocalOptions object that exposes the options that are available for DynamoDB local.
If you want the tables and data to persist between .NET Aspire debug sessions, set the LocalStorageDirectory property on the DynamoDBLocalOptions object to a local folder where the data will be persisted. The AddAWSDynamoDBLocal method will take care of mounting the local directory to the container and configuring the DynamoDB local process to use the mount point.
Note: This feature requires
net10.0and is behind theASPIREAWSAGENTCORE001experimental flag.
The AgentCore integration provides a local development experience for agents built with the AWS.AgentCore.Hosting package. All emulators run as embedded in-process Kestrel servers — no Docker or separate processes required.
Add the AWS.AgentCore.Hosting package to your agent project:
dotnet add package AWS.AgentCore.Hosting
Use the annotations or extension methods to define your agent. Then in your Aspire AppHost, add a reference to Aspire.Hosting.AWS and configure your agents:
#pragma warning disable ASPIREAWSAGENTCORE001
var builder = DistributedApplication.CreateBuilder(args);
// Register a non-streaming agent with short-term memory
var agent = builder.AddAgentCoreRuntime<Projects.MyAgent>("my-agent")
.WithInMemory();
// Register a streaming agent
builder.AddAgentCoreRuntime<Projects.MyStreamingAgent>("my-streaming-agent")
.WithStreaming()
.WithInMemory();
// Wire a consumer project — AWS_ENDPOINT_URL_BEDROCK_AGENTCORE is injected automatically
builder.AddProject<Projects.MyChatUI>("ChatUI")
.WithReference(agent);
builder.Build().Run();
| Method | Description |
|---|---|
AddAgentCoreRuntime<TProject>() |
Registers an agent with embedded runtime and chat emulators |
.WithStreaming() |
Enables SSE streaming mode for the chat app |
.WithInMemory() |
Adds a short-term memory emulator |
.WithReference(agent) |
Injects the runtime emulator endpoint into a consumer project via AWS_ENDPOINT_URL_BEDROCK_AGENTCORE |
builder.AddAgentCoreRuntime<Projects.MyAgent>("my-agent",
new AgentCoreLocalOptions
{
IncludeEmulatorLogs = true, // Route emulator logs to the Aspire dashboard
RuntimeEmulatorPort = 9000, // Pin the runtime emulator port (default: OS-assigned)
ChatAppPort = 9001, // Pin the chat app port (default: OS-assigned)
MemoryEmulatorPort = 9002 // Pin the memory emulator port (default: OS-assigned)
});
When the Aspire AppHost starts, each AddAgentCoreRuntime call:
The Aspire dashboard shows clickable URLs for each emulator alongside your agent resource.
https://github.com/aws/integrations-on-dotnet-aspire-for-aws
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on Aspire.Hosting.AWS:
| Package | Downloads |
|---|---|
|
LocalStack.Aspire.Hosting
.NET Aspire integration for LocalStack - enables local AWS service development and testing with auto-configuration, container orchestration, and full compatibility with Aspire.Hosting.AWS patterns. |
|
|
Altemiq.Aspire.Hosting.AWS.Configuration
AWS Configuration support for .NET Aspire. |
|
|
McDoit.Aspire.Hosting.Ministack
Contains wrappers for using Ministack with Aspire |
|
|
Altemiq.Aspire.Hosting.LocalStack
LocalStack support for .NET Aspire. |
|
|
McDoit.Aspire.Hosting.Ministack.Sample.CloudFormation.AppHost
Contains wrappers for using Ministack with Aspire |
Showing the top 1 popular GitHub repositories that depend on Aspire.Hosting.AWS:
| Repository | Stars |
|---|---|
|
aws/aws-dotnet-messaging
An AWS-native framework that simplifies the development of .NET message processing applications that use AWS services, such as SQS, SNS, and EventBridge.
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 13.3.0 | 8 | 6/17/2026 | |
| 13.2.0 | 14,732 | 5/14/2026 | |
| 13.1.0 | 1,471 | 5/13/2026 | |
| 13.0.2 | 8,149 | 5/5/2026 | |
| 13.0.1 | 4,328 | 4/29/2026 | |
| 13.0.0 | 58,300 | 2/26/2026 | |
| 9.4.1 | 7,953 | 2/23/2026 | |
| 9.4.0 | 6,879 | 2/19/2026 | |
| 9.3.2 | 8,984 | 2/5/2026 | |
| 9.3.1 | 17,630 | 1/26/2026 | |
| 9.3.0 | 175,729 | 10/28/2025 | |
| 9.2.6 | 79,620 | 7/18/2025 | |
| 9.2.5 | 5,267 | 6/27/2025 | |
| 9.2.4 | 1,826 | 6/23/2025 | |
| 9.2.3 | 4,327 | 6/12/2025 | |
| 9.2.2 | 11,150 | 5/19/2025 | |
| 9.2.1 | 2,981 | 5/8/2025 | 9.2.1 is deprecated because it is no longer maintained. |
| 9.2.0 | 3,032 | 5/6/2025 | 9.2.0 is deprecated because it is no longer maintained. |
| 9.1.9 | 23,875 | 4/23/2025 | 9.1.9 is deprecated because it is no longer maintained. |
| 9.1.8 | 5,652 | 4/11/2025 | 9.1.8 is deprecated because it is no longer maintained. |