-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2557b24
commit 51f5dff
Showing
3 changed files
with
34 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { STSClient } from '@aws-sdk/client-sts' | ||
import { beforeAll, describe, expect, it } from 'vitest' | ||
import { registerDependencies } from '../../test/utils/testContext' | ||
import { buildTopicArn } from './stsUtils' | ||
|
||
describe('stsUtils', () => { | ||
let stsClient: STSClient | ||
|
||
beforeAll(async () => { | ||
const diContainer = await registerDependencies({}, false) | ||
stsClient = diContainer.cradle.stsClient | ||
}) | ||
|
||
describe('buildTopicArn', () => { | ||
it('build ARN for topic', async () => { | ||
const topicName = 'my-test-topic' | ||
await expect(buildTopicArn(stsClient, topicName)).resolves.toMatchInlineSnapshot(`"arn:aws:sns:eu-west-1:000000000000:my-test-topic"`) | ||
}) | ||
}) | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { GetCallerIdentityCommand, type STSClient } from '@aws-sdk/client-sts' | ||
|
||
/** | ||
* Manually builds the ARN of a topic based on the current AWS account and the topic name. | ||
* It follows the following pattern: arn:aws:sns:<region>:<account-id>:<topic-name> | ||
* Doc -> https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html | ||
*/ | ||
export const buildTopicArn = async (client: STSClient, topicName: string) => { | ||
const identityResponse = await client.send(new GetCallerIdentityCommand({})) | ||
const region = | ||
typeof client.config.region === 'string' ? client.config.region : await client.config.region() | ||
|
||
return `arn:aws:sns:${region}:${identityResponse.Account}:${topicName}` | ||
} |