Queue.fromArn breaks the queueUrl resolution
When running localstack with docker, my SQS Queue's are configured so that their URL's are meant to look like:
$ awslocal sqs create-queue --queue-name test
{
"QueueUrl": "http://172.26.0.2:4566/000000000000/test"
}
When I pass SQS queue's between stacks, I need to pass in the queue's arn and then fetch the queue with Queue.fromArn. When you pull a queue from Arn the queueUrl has a resolve that makes it look much different (https://sqs.${Token[TOKEN.207]}.${Token[AWS.URLSuffix.5]}/${Token[TOKEN.208]}/${Token[TOKEN.209]}). This leads to not being able to use the URL's from SQS Queues that are passed between stacks.
version: "3.5"
services:
localstack:
container_name: "localstack"
image: localstack/localstack:latest
network_mode: bridge
ports:
- "433:433"
- "4566:4566"
- "4567:4567"
- "4571:4571"
- "9001:9001"
environment:
- SERVICES=sqs, lambda, apigateway, s3, sts, ssm, sns, ses, cloudformation, iam, ec2, kms, cloudfront
- LOCALSTACK_HOSTNAME=172.26.0.2
- HOSTNAME=172.26.0.2
- HOSTNAME_EXTERNAL=172.26.0.2
- LAMBDA_EXECUTOR=docker
- LAMBDA_REMOTE_DOCKER=true
- DOCKER_HOST=unix:///var/run/docker.sock
- DEFAULT_REGION=eu-west-2
- TEST_AWS_ACCOUNT_ID=000000000000
- DEBUG=1
volumes:
- "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
import { App, Stack } from "aws-cdk-lib";
import { Construct } from "constructs";
import { Queue } from "aws-cdk-lib/aws-sqs";
import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda";
class TestStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
const producer = new ProducerConstruct(this, "producer");
new ConsumerConstruct(this, "consumer", producer.queue.queueArn);
}
}
class ProducerConstruct extends Construct {
public readonly queue: Queue;
constructor(scope: Construct, id: string) {
super(scope, id);
this.queue = new Queue(this, "Queue");
}
}
class ConsumerConstruct extends Construct {
constructor(scope: Construct, id: string, queueArn: string) {
super(scope, id);
const queue = Queue.fromQueueArn(this, "queue", queueArn);
new Function(this, "lambda", {
runtime: Runtime.NODEJS_14_X,
handler: "index.handler",
code: Code.fromAsset(""),
environment: {
SQS_QUEUE_URL: queue.queueUrl,
},
});
}
}
const app = new App();
new TestStack(app, "stack");
From my understanding this comes from Queue.fromQueueAttributes where it defaults the queueUrl to https://sqs.${parsedArn.region}.${stack.urlSuffix}/${parsedArn.account}/${queueName} if you don't pass one in. I would assume this would need patching to match the SQS Queue Url Strategy that you set up in localstack
Hi! We just wanted to follow up to see whether your issue has been resolved. Were you able to get it working with the latest version of LocalStack? We would appreciate your feedback!