Created
September 8, 2023 17:10
-
-
Save varqasim/362a8f77af28b771a07b409006983a86 to your computer and use it in GitHub Desktop.
Get AWS SQS URL from SQS Arn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getQueueUrl(accountId: string, queueArn: string) { | |
const regex = new RegExp(`${accountId}:`); | |
const queueName = queueArn.split(regex)[1]; | |
return `https://sqs.${process.env.AWS_REGION}.amazonaws.com/${accountId}/${queueName}` | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import STS from 'aws-sdk/clients/sts'; | |
import Lambda from 'aws-sdk/clients/lambda'; | |
import SQS from 'aws-sdk/clients/sqs'; | |
let accountId: string; | |
beforeAll(async () => { | |
const sts = new STS({ region: process.env.AWS_REGION }); | |
const { Account: account } = await sts.getCallerIdentity({}).promise(); | |
accountId = account!; | |
}); | |
test('myTest', async () => { | |
const lambdaFuncESM = await lambdaClient | |
.listEventSourceMappings({ FunctionName: 'myFuncName' }).promise(); | |
const queueArn = lambdaFuncESM.EventSourceMappings![0].EventSourceArn!; | |
const queueUrl = getQueueUrl(accountId, queueArn); | |
console.log({ queueArn, queueUrl }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment