Skip to content

Implement IResourceWithParent for the LambdaProjectResource #103

@jeastham1993

Description

@jeastham1993

When Lambda functions are running, they are children of the LambdaServiceEmulator inside Aspire. However, the LambdaProjectResource itself doesn't have the parent relationship.

The use case here is to get the Lambda Test Tool Endpoint as part of running Aspire tests.

Currently, to do this you need to:

var lambdaServiceEmulatorResource = builder.Resources.FirstOrDefault(resource => resource.Name == "LambdaServiceEmulator")!;

var endpoints = lambdaServiceEmulatorResource.TryGetEndpoints(out var endpointsList)
                ? endpointsList
                : throw new InvalidOperationException("Lambda service emulator does not have an HTTP endpoint configured.");

            var connectionString = endpoints.FirstOrDefault()!.AllocatedEndpoint!.UriString;
            return new AmazonLambdaClient(new BasicAWSCredentials("dummykey", "dummysecret"), new AmazonLambdaConfig()
            {
                ServiceURL = connectionString
            });

But it would be great to be able to call lambdaResource.Parent.GetEndpoint().

Example Implementations

The Azure Service Bus resources do support this

public class AzureServiceBusQueueResource(string name, string queueName, AzureServiceBusResource parent)
    : Resource(name), IResourceWithParent<AzureServiceBusResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig
{
}

which then allows you to write code like this to get the connection string for service bus:

var connectionString = await builder.Resource.Parent.ConnectionStringExpression
                .GetValueAsync(CancellationToken.None)

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestA feature should be added or improved.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions