Partager via


CDKExtensions.WithEnvironment<TDestination,TConstruct> Method

Definition

Add an environment variable with a reference of a AWS CDK construct to a project. The output parameters of the CloudFormation stack are added to the project IConfiguration.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<TDestination> WithEnvironment<TDestination,TConstruct> (this Aspire.Hosting.ApplicationModel.IResourceBuilder<TDestination> builder, string name, Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.AWS.CDK.IResourceWithConstruct<TConstruct>> construct, Aspire.Hosting.AWS.CDK.ConstructOutputDelegate<TConstruct> outputDelegate, string? outputName = default) where TDestination : Aspire.Hosting.ApplicationModel.IResourceWithEnvironment where TConstruct : Constructs.IConstruct;
static member WithEnvironment : Aspire.Hosting.ApplicationModel.IResourceBuilder<'Destination (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)> * string * Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.AWS.CDK.IResourceWithConstruct<'Construct>> * Aspire.Hosting.AWS.CDK.ConstructOutputDelegate<'Construct (requires 'Construct :> Constructs.IConstruct)> * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'Destination (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)> (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment and 'Construct :> Constructs.IConstruct)
<Extension()>
Public Function WithEnvironment(Of TDestination As IResourceWithEnvironment, TConstruct As IResourceWithEnvironment) (builder As IResourceBuilder(Of TDestination), name As String, construct As IResourceBuilder(Of IResourceWithConstruct(Of TConstruct)), outputDelegate As ConstructOutputDelegate(Of TConstruct), Optional outputName As String = Nothing) As IResourceBuilder(Of TDestination)

Type Parameters

TDestination
TConstruct

Parameters

builder
IResourceBuilder<TDestination>

The resource builder.

name
String

The name of the environment variable.

construct
IResourceBuilder<IResourceWithConstruct<TConstruct>>

The construct resource.

outputDelegate
ConstructOutputDelegate<TConstruct>

The construct output delegate.

outputName
String

The name of the construct output

Returns

IResourceBuilder<TDestination>

Examples

The following example shows creating a custom construct and reference the exposed ServiceUrl property in a project as environment variable.

var service = stack.AddConstruct("service", scope => new Service(scope, "service");
var api = builder.AddProject<Projects.Api>("api")
    .WithEnvironment("Service_ServiceUrl", service, s => s.ServiceUrl);

Applies to