Skip to content
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

Add AWS CDK support #2225

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b97fd81
Initial AWS CDK Support
Apr 12, 2024
a3ecee3
Add documentation and additional resources
Apr 30, 2024
6164785
Make properties optional
Apr 30, 2024
77d56cb
Add Amazon Kinesis streams
May 1, 2024
306e022
Merge branch 'main' into vlesierse/aws-cdk
May 8, 2024
756fea0
Add bucket notifications and topic subscriptions
May 8, 2024
be9136a
Adding this for extension methods
May 8, 2024
925b358
Fix await stack resource
vlesierse May 15, 2024
6120522
Allow multiple reference to same construct resource
vlesierse May 15, 2024
953c11e
Merge branch 'main' into vlesierse/aws-cdk
vlesierse May 22, 2024
e74cbf0
Refactoring after code review
May 29, 2024
f54ee37
Cleanup
May 29, 2024
4063577
Changes after code review
May 30, 2024
c606bb3
Provide guidance for missing CDK bootstrap
Jun 10, 2024
4cf0b37
Merge AWSCDK in AWS playground
Jun 11, 2024
4b6ae98
Merge branch 'main' into vlesierse/aws-cdk
Jun 12, 2024
98feb7e
Merge branch 'main' into vlesierse/aws-cdk
Jun 13, 2024
6ff3a61
Changes after code review
Jun 13, 2024
9668b80
Remove support restrictions
Jun 13, 2024
38433e6
Simplified construct/stack outputs
Jun 13, 2024
e691101
Include output changes
Jun 13, 2024
2b25719
Introduce new provisioners
Jun 19, 2024
9f71622
CloudFormation provisioners
vlesierse Jun 20, 2024
2a4d1e9
Refactor CloudFormation executor
Jun 20, 2024
77ef4ec
Add AWS CDK Provisioning
vlesierse Jun 21, 2024
e7e50d5
Change manifest to include the right stack name
vlesierse Jun 21, 2024
bc5daa1
Fix manifest values
vlesierse Jun 21, 2024
6850b46
Support dev environments with spaces
vlesierse Jun 21, 2024
29cebe5
Add tests for CDK resources
Jun 21, 2024
95f55af
Add CDK documentation to README.md
Jun 21, 2024
9329a9c
Changes after code review
Jun 23, 2024
821a6cf
Changes after code review
Jul 5, 2024
910e762
Additional changes after code review
Jul 5, 2024
dd45fb9
Refactor and simplify CDK stack provisioning
Jul 6, 2024
98e94ba
Merge branch 'main' into vlesierse/aws-cdk
Jul 7, 2024
6ce231a
Remove AWSSDK SSO
Jul 7, 2024
4e9338a
Fix build
Jul 8, 2024
04f0571
Merge branch 'main' into vlesierse/aws-cdk
Jul 24, 2024
1dadf75
Changes after code review
Aug 24, 2024
8c961ec
Merge branch 'main' into vlesierse/aws-cdk
vlesierse Aug 24, 2024
2667b19
Add missing merge changes
vlesierse Aug 24, 2024
a92f4fb
Fix AWSCloudFormationResourceTests
vlesierse Aug 24, 2024
04b1b3c
Remove Aspire- prefix from AddAWSCloudFormationStack
vlesierse Aug 24, 2024
3d6a837
Fix packages due to merge
vlesierse Aug 24, 2024
bb12ea2
Bump AWS CDK
vlesierse Aug 24, 2024
54117f3
Temp solution to verify build
Aug 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrleansClient", "playground
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrleansContracts", "playground\orleans\OrleansContracts\OrleansContracts.csproj", "{75760E8A-7025-4F6A-B152-6622688D0E7D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AWSCDK", "AWSCDK", "{CB625B60-00EE-48D9-8240-4A759F7D05F7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWSCDK.ServiceDefaults", "playground\AWSCDK\AWSCDK.ServiceDefaults\AWSCDK.ServiceDefaults.csproj", "{98C3185B-960A-47FC-99C3-00C15BDE1ED6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApp", "playground\AWSCDK\WebApp\WebApp.csproj", "{69D57F56-C552-4573-9018-DDA5D3C52A6E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWSCDK.AppHost", "playground\AWSCDK\AWSCDK.AppHost\AWSCDK.AppHost.csproj", "{A2970C5C-9C5A-4B92-B966-E97F81D05A73}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1173,6 +1181,18 @@ Global
{75760E8A-7025-4F6A-B152-6622688D0E7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75760E8A-7025-4F6A-B152-6622688D0E7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75760E8A-7025-4F6A-B152-6622688D0E7D}.Release|Any CPU.Build.0 = Release|Any CPU
{98C3185B-960A-47FC-99C3-00C15BDE1ED6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98C3185B-960A-47FC-99C3-00C15BDE1ED6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98C3185B-960A-47FC-99C3-00C15BDE1ED6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98C3185B-960A-47FC-99C3-00C15BDE1ED6}.Release|Any CPU.Build.0 = Release|Any CPU
{69D57F56-C552-4573-9018-DDA5D3C52A6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69D57F56-C552-4573-9018-DDA5D3C52A6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69D57F56-C552-4573-9018-DDA5D3C52A6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69D57F56-C552-4573-9018-DDA5D3C52A6E}.Release|Any CPU.Build.0 = Release|Any CPU
{A2970C5C-9C5A-4B92-B966-E97F81D05A73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2970C5C-9C5A-4B92-B966-E97F81D05A73}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2970C5C-9C5A-4B92-B966-E97F81D05A73}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2970C5C-9C5A-4B92-B966-E97F81D05A73}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1386,6 +1406,10 @@ Global
{8191109E-130C-47F3-B84E-82070A6CD269} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
{906B5687-31AD-4364-AD9F-B4B26113462D} = {8BAF2119-8370-4E9E-A887-D92506F8C727}
{75760E8A-7025-4F6A-B152-6622688D0E7D} = {8BAF2119-8370-4E9E-A887-D92506F8C727}
{CB625B60-00EE-48D9-8240-4A759F7D05F7} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
{98C3185B-960A-47FC-99C3-00C15BDE1ED6} = {CB625B60-00EE-48D9-8240-4A759F7D05F7}
{69D57F56-C552-4573-9018-DDA5D3C52A6E} = {CB625B60-00EE-48D9-8240-4A759F7D05F7}
{A2970C5C-9C5A-4B92-B966-E97F81D05A73} = {CB625B60-00EE-48D9-8240-4A759F7D05F7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}
Expand Down
3 changes: 3 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<!-- AWS SDK for .NET dependencies -->
<PackageVersion Include="AWSSDK.CloudFormation" Version="3.7.306.3" />
<PackageVersion Include="AWSSDK.DynamoDBv2" Version="3.7.302.6" />
<PackageVersion Include="AWSSDK.SQS" Version="3.7.300.71" />
<PackageVersion Include="AWSSDK.SimpleNotificationService" Version="3.7.301.19" />
<PackageVersion Include="AWSSDK.Core" Version="3.7.303.11" />
Expand All @@ -18,6 +19,8 @@
<PackageVersion Include="Azure.Messaging.EventHubs.Processor" Version="5.11.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AWS" Version="1.1.0-beta.3" />
<PackageVersion Include="OpenTelemetry.Extensions.AWS" Version="1.3.0-beta.1" />
<!-- AWS CDK dependencies -->
<PackageVersion Include="Amazon.CDK.Lib" Version="2.133.0" />
<!-- Azure SDK for .NET dependencies -->
<PackageVersion Include="Azure.AI.OpenAI" Version="1.0.0-beta.15" />
<PackageVersion Include="Azure.Data.Tables" Version="12.8.3" />
Expand Down
4 changes: 4 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
Copy link
Member

Choose a reason for hiding this comment

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

❗ We can't pull packages from nuget.org.
This will have to be removed before this PR can get merged.

<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
<!-- Begin: Package sources from dotnet-aspnetcore -->
<!-- End: Package sources from dotnet-aspnetcore -->
Expand All @@ -21,6 +22,9 @@
<add key="dotnet9-transport" value="https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet9-transport/nuget/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
<packageSource key="dotnet9-transport">
<package pattern="*WorkloadBuildTasks*" />
</packageSource>
Expand Down
22 changes: 22 additions & 0 deletions playground/AWSCDK/AWSCDK.AppHost/AWSCDK.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsAspireHost>true</IsAspireHost>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(SharedDir)KnownResourceNames.cs" Link="KnownResourceNames.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Aspire.Dashboard\Aspire.Dashboard.csproj" />
<ProjectReference Include="..\..\..\src\Aspire.Hosting.AWS\Aspire.Hosting.AWS.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\..\..\src\Aspire.Hosting\Aspire.Hosting.csproj" IsAspireProjectResource="false" />

<ProjectReference Include="..\WebApp\WebApp.csproj" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions playground/AWSCDK/AWSCDK.AppHost/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<!-- NOTE: This line is only required because we are using P2P references, not NuGet. It will not exist in real apps. -->
<Import Project="../../../src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.props" />

</Project>
9 changes: 9 additions & 0 deletions playground/AWSCDK/AWSCDK.AppHost/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />

<!-- NOTE: These lines are only required because we are using P2P references, not NuGet. They will not exist in real apps. -->
<Import Project="..\..\..\src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.targets" />
<Import Project="..\..\..\src\Aspire.Hosting.Sdk\SDK\Sdk.targets" />

</Project>
39 changes: 39 additions & 0 deletions playground/AWSCDK/AWSCDK.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Amazon;
using Amazon.CDK;
using Amazon.CDK.AWS.DynamoDB;
using Attribute = Amazon.CDK.AWS.DynamoDB.Attribute;

var builder = DistributedApplication.CreateBuilder(args).WithAWSCDK();

// Setup a configuration for the AWS .NET SDK.
var awsConfig = builder.AddAWSSDKConfig()
.WithProfile("default")
.WithRegion(RegionEndpoint.EUWest1);

/*var stack = builder.AddStack(
app => new WebAppStack(app, "AspireWebAppStack", new WebAppStackProps()))
.WithOutput("TableName", s => s.Table.TableName)
.WithReference(awsConfig);*/

var stack = builder.AddStack("Stack").WithReference(awsConfig);
var table = stack.AddDynamoDBTable("Table", new TableProps
{
PartitionKey = new Attribute { Name = "id", Type = AttributeType.STRING },
BillingMode = BillingMode.PAY_PER_REQUEST,
RemovalPolicy = RemovalPolicy.DESTROY
})
.AddGlobalSecondaryIndex(new GlobalSecondaryIndexProps
{
IndexName = "OwnerIndex",
PartitionKey = new Attribute { Name = "owner", Type = AttributeType.STRING },
SortKey = new Attribute { Name = "ownerSK", Type = AttributeType.STRING },
ProjectionType = ProjectionType.ALL
});

builder.AddProject<Projects.WebApp>("webapp")
.WithReference(table);
//.WithEnvironment("AWS__Resources__TableName", table.GetOutput("TableName", t => t.TableName));
//.WithEnvironment("AWS__Resources__TableName", table, t => t.TableName);
//.WithReference(table);

builder.Build().Run();
29 changes: 29 additions & 0 deletions playground/AWSCDK/AWSCDK.AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:15069",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:16216",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"publish": {
"commandName": "Project",
"commandLineArgs": "--publisher manifest --output-path ./aspire-manifest.json",
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:15069",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:16216",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
}
}
}
26 changes: 26 additions & 0 deletions playground/AWSCDK/AWSCDK.AppHost/WebAppStack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Amazon.CDK;
using Amazon.CDK.AWS.DynamoDB;
using Constructs;
using Attribute = Amazon.CDK.AWS.DynamoDB.Attribute;

namespace AWSCDK.AppHost;

public class WebAppStackProps : StackProps;

public class WebAppStack : Stack
{
public ITable Table { get; }

public WebAppStack(Construct scope, string id, WebAppStackProps props)
: base(scope, id, props)
{
Table = new Table(this, "Table", new TableProps
{
PartitionKey = new Attribute { Name = "id", Type = AttributeType.STRING },
BillingMode = BillingMode.PAY_PER_REQUEST
});
}
}
33 changes: 33 additions & 0 deletions playground/AWSCDK/AWSCDK.AppHost/aspire-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"resources": {
"Stack": {
"error": "This resource does not support generation in the manifest."
},
"Table": {
"error": "This resource does not support generation in the manifest."
},
"webapp": {
"type": "project.v0",
"path": "../WebApp/WebApp.csproj",
"env": {
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true",
"OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY": "in_memory",
"ASPNETCORE_FORWARDEDHEADERS_ENABLED": "true",
"AWS__Resources__TableName": "{Stack.output.Table706B9215TableName}"
},
"bindings": {
"http": {
"scheme": "http",
"protocol": "tcp",
"transport": "http"
},
"https": {
"scheme": "https",
"protocol": "tcp",
"transport": "http"
}
}
}
}
}
63 changes: 63 additions & 0 deletions playground/AWSCDK/AWSCDK.AppHost/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"app": "dotnet run -- --publisher manifest --output-path ./aspire-manifest.json",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"src/*/obj",
"src/*/bin",
"src/*.sln",
"src/*/GlobalSuppressions.cs",
"src/*/*.csproj"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk/aws-redshift:columnId": true,
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
"@aws-cdk/aws-kms:aliasNameRef": true,
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />

<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />

<PackageReference Include="Microsoft.Extensions.Http.Resilience" />

<PackageReference Include="OpenTelemetry.Instrumentation.AWS" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Microsoft.Extensions.ServiceDiscovery.Dns\Microsoft.Extensions.ServiceDiscovery.Dns.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.Extensions.ServiceDiscovery\Microsoft.Extensions.ServiceDiscovery.csproj" />
</ItemGroup>

</Project>
Loading