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

Lambda + SQS examples/best practices #627

Closed
1 task done
xtaixe opened this issue May 26, 2022 · 3 comments
Closed
1 task done

Lambda + SQS examples/best practices #627

xtaixe opened this issue May 26, 2022 · 3 comments

Comments

@xtaixe
Copy link

xtaixe commented May 26, 2022

Is there an existing issue for this?

  • I have searched the existing issues and read the documentation

Question

Are there any examples or guides around best practices when using Lambdas and SQS queues?

In our case we need to access the related SQS queues both from localhost and from the Lambdas, but what we are doing seems rather complex. We are using LocalStack through TestContainers and we configure LocalStack as follows:

final Network network = Network.newNetwork();

final LocalStackContainer localStackContainer = new LocalStackContainer(DockerImageName.parse("localstack/localstack:0.14.3"))
    .withEnv("LAMBDA_EXECUTOR", "docker")
    // network name is generated as random uuid inside NetworkImpl
    // but the Network interface does not have a method to get name so we need to cast
    .withEnv("LAMBDA_DOCKER_NETWORK", ((Network.NetworkImpl) network).getName())
    .withEnv("HOSTNAME_EXTERNAL", "localhost")
    .withNetwork(network)
    .withNetworkAliases("localstack")
    .withServices(LAMBDA, SQS);

Then we create the necessary SQS queues through an AWS SQS client and retrieve their URL.

Then we pass the URLs to Lambdas through environment variables when creating them, but for the Lambdas to use the right URLs we need to do the following:

url
    .replaceAll("localhost:\\d+", "localstack:4566")
    .replaceAll("127.0.0.1:\\d+", "localstack:4566");

Is there a simpler way? Thanks.

@thrau thrau removed their assignment Sep 3, 2022
@thrau
Copy link
Member

thrau commented Mar 17, 2023

localstack/localstack#7774 should help with this, together with #444

@thrau thrau transferred this issue from localstack/localstack May 10, 2023
@thrau
Copy link
Member

thrau commented May 10, 2023

I've transferred the issue to our docs repository. I think there is some value in adding specific examples to the SQS service page.

@thrau
Copy link
Member

thrau commented Jul 28, 2023

with the new lambda provider of 2.0, SQS endpoint resolution now works out of the box when using SQS_ENDPOINT_STRATEGY=domain. This vastly simplifies the configuration, and have added a short section on this to the SQS docs: #731.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants