public static IResourceBuilder WithEnvironment()

in src/Aspire.Hosting.AWS/CloudFormation/CloudFormationExtensions.cs [91:116]


    public static IResourceBuilder<T> WithEnvironment<T>(this IResourceBuilder<T> builder, string name, StackOutputReference stackOutputReference)
        where T : IResourceWithEnvironment
    {
        if (!stackOutputReference.Resource.Annotations.Any(x => x is CloudFormationReferenceAnnotation cf && string.Equals(cf.TargetResource, builder.Resource.Name, StringComparison.Ordinal)))
        {
            stackOutputReference.Resource.Annotations.Add(new CloudFormationReferenceAnnotation(builder.Resource.Name));
        }

        return builder.WithEnvironment(async ctx =>
        {
            if (ctx.ExecutionContext.IsPublishMode)
            {
                ctx.EnvironmentVariables[name] = stackOutputReference.ValueExpression;
                return;
            }

            if (stackOutputReference.Resource.AWSSDKConfig != null)
            {
                SdkUtilities.ApplySDKConfig(ctx, stackOutputReference.Resource.AWSSDKConfig, false);
            }

            ctx.Logger?.LogInformation("Getting CloudFormation stack output {Name} from resource {ResourceName}", stackOutputReference.Name, stackOutputReference.Resource.Name);

            ctx.EnvironmentVariables[name] = await stackOutputReference.GetValueAsync(ctx.CancellationToken).ConfigureAwait(false) ?? "";
        });
    }