@tomassabol/aws-services 1.8.0 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/appconfig.d.ts +3 -0
- package/appconfig.js +18 -0
- package/dynamodb.d.ts +4 -0
- package/dynamodb.js +7 -0
- package/dynamodb.mock.d.ts +8 -0
- package/dynamodb.mock.js +12 -0
- package/eventbridge.d.ts +8 -0
- package/eventbridge.js +37 -0
- package/eventbridge.mock.d.ts +3 -0
- package/eventbridge.mock.js +7 -0
- package/logger.d.ts +2 -0
- package/logger.js +14 -0
- package/package.json +8 -9
- package/s3.d.ts +13 -0
- package/s3.js +46 -0
- package/secrets-manager.d.ts +4 -0
- package/secrets-manager.js +37 -0
- package/secrets-manager.mock.d.ts +4 -0
- package/secrets-manager.mock.js +8 -0
- package/sns.d.ts +7 -0
- package/sns.js +21 -0
- package/sqs.d.ts +6 -0
- package/sqs.js +24 -0
- package/sqs.mock.d.ts +3 -0
- package/sqs.mock.js +7 -0
- package/ssm.d.ts +19 -0
- package/ssm.js +48 -0
- package/ssm.mock.d.ts +3 -0
- package/ssm.mock.js +7 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -75
- package/.husky/pre-commit +0 -4
- package/.lintstagedrc.json +0 -9
- package/.nvmrc +0 -1
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -3
- package/.vscode/settings.json +0 -6
- package/CHANGELOG.md +0 -96
- package/bitbucket-pipelines.yml +0 -65
- package/jest.config.js +0 -62
- package/sonar-project.properties +0 -8
- package/src/appconfig.ts +0 -20
- package/src/dynamodb.mock.ts +0 -10
- package/src/dynamodb.ts +0 -7
- package/src/eventbridge.mock.ts +0 -5
- package/src/eventbridge.ts +0 -47
- package/src/logger.ts +0 -14
- package/src/s3.ts +0 -56
- package/src/secrets-manager.mock.ts +0 -9
- package/src/secrets-manager.ts +0 -37
- package/src/sns.ts +0 -24
- package/src/sqs.mock.ts +0 -5
- package/src/sqs.ts +0 -32
- package/src/ssm.mock.ts +0 -5
- package/src/ssm.ts +0 -70
- package/test/appconfig.test.ts +0 -45
- package/test/dynamodb.test.ts +0 -13
- package/test/eventbridge.test.ts +0 -35
- package/test/s3.test.ts +0 -78
- package/test/secrets-manager.test.ts +0 -55
- package/test/sns.test.ts +0 -59
- package/test/sqs.test.ts +0 -46
- package/test/ssm.test.ts +0 -85
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -9
- package/typedoc.json +0 -4
package/CHANGELOG.md
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
-
|
|
8
|
-
## [1.8.0] - 2024-06-24
|
|
9
|
-
|
|
10
|
-
### Changed
|
|
11
|
-
|
|
12
|
-
- WMS-488 Improve sendEvent error handling
|
|
13
|
-
|
|
14
|
-
## [1.7.1] - 2024-06-22
|
|
15
|
-
|
|
16
|
-
### Changed
|
|
17
|
-
|
|
18
|
-
- Bump @aws-lambda-powertools/logger
|
|
19
|
-
|
|
20
|
-
### Security
|
|
21
|
-
|
|
22
|
-
- Remove NPM token
|
|
23
|
-
|
|
24
|
-
## [1.7.0] - 2023-11-18
|
|
25
|
-
|
|
26
|
-
### Added
|
|
27
|
-
|
|
28
|
-
- Add Jest mock for SSM
|
|
29
|
-
|
|
30
|
-
## [1.6.1] - 2023-11-04
|
|
31
|
-
|
|
32
|
-
### Added
|
|
33
|
-
|
|
34
|
-
- Add getSecret method to Secrets Manager mock
|
|
35
|
-
|
|
36
|
-
### Security
|
|
37
|
-
|
|
38
|
-
- Fix vulnerabilities
|
|
39
|
-
|
|
40
|
-
## [1.6.0] - 2023-08-18
|
|
41
|
-
|
|
42
|
-
### Added
|
|
43
|
-
|
|
44
|
-
- Add Jest mocks for DynamoDB, EventBridge, Secrets Manager and SQS
|
|
45
|
-
|
|
46
|
-
## [1.5.0] - 2023-08-14
|
|
47
|
-
|
|
48
|
-
### Changed
|
|
49
|
-
|
|
50
|
-
- Improve S3 client
|
|
51
|
-
|
|
52
|
-
## [1.4.0] - 2023-08-12
|
|
53
|
-
|
|
54
|
-
### Changed
|
|
55
|
-
|
|
56
|
-
- Improve EventBridge client
|
|
57
|
-
|
|
58
|
-
## [1.3.0] - 2023-08-11
|
|
59
|
-
|
|
60
|
-
### Added
|
|
61
|
-
|
|
62
|
-
- Add format check step to Bitbucket pipeline
|
|
63
|
-
- Add nvm configuration file
|
|
64
|
-
|
|
65
|
-
### Changed
|
|
66
|
-
|
|
67
|
-
- Improve SSM client
|
|
68
|
-
- Improve SQS client
|
|
69
|
-
- Improve Secrets Manager client
|
|
70
|
-
- Improve DynamoDB client
|
|
71
|
-
- Upgrade AWS CDK libs
|
|
72
|
-
- Refactor NPM scripts
|
|
73
|
-
- Update nvm configuration file
|
|
74
|
-
- Improve Bitbucket pipeline
|
|
75
|
-
|
|
76
|
-
### Removed
|
|
77
|
-
|
|
78
|
-
- Remove npm-run-all package
|
|
79
|
-
|
|
80
|
-
### Security
|
|
81
|
-
|
|
82
|
-
- Fix vulnerabilities
|
|
83
|
-
|
|
84
|
-
## [1.2.1] - 2023-06-08
|
|
85
|
-
|
|
86
|
-
### Fixed
|
|
87
|
-
|
|
88
|
-
- Fix importing without dist folder
|
|
89
|
-
|
|
90
|
-
### Security
|
|
91
|
-
|
|
92
|
-
- Fix vulnerabilities
|
|
93
|
-
|
|
94
|
-
## [1.1.1]
|
|
95
|
-
|
|
96
|
-
- Initial release
|
package/bitbucket-pipelines.yml
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
image: node:18
|
|
2
|
-
|
|
3
|
-
definitions:
|
|
4
|
-
steps:
|
|
5
|
-
- step: &build-step
|
|
6
|
-
name: Build
|
|
7
|
-
caches:
|
|
8
|
-
- node
|
|
9
|
-
script:
|
|
10
|
-
- npm ci
|
|
11
|
-
- step: &format-step
|
|
12
|
-
name: Format
|
|
13
|
-
caches:
|
|
14
|
-
- node
|
|
15
|
-
script:
|
|
16
|
-
- npm run format
|
|
17
|
-
- step: &lint-step
|
|
18
|
-
name: Lint
|
|
19
|
-
caches:
|
|
20
|
-
- node
|
|
21
|
-
script:
|
|
22
|
-
- npm run lint
|
|
23
|
-
- step: &test-step
|
|
24
|
-
name: Test
|
|
25
|
-
caches:
|
|
26
|
-
- node
|
|
27
|
-
script:
|
|
28
|
-
- npm test
|
|
29
|
-
artifacts:
|
|
30
|
-
- .coverage/lcov.info
|
|
31
|
-
- .sonar/test-report.xml
|
|
32
|
-
- step: &code-analysis-step
|
|
33
|
-
name: Code Analysis
|
|
34
|
-
caches:
|
|
35
|
-
- sonar
|
|
36
|
-
script:
|
|
37
|
-
- pipe: sonarsource/sonarqube-scan:2.0.1
|
|
38
|
-
variables:
|
|
39
|
-
SONAR_HOST_URL: ${SONAR_HOST_URL}
|
|
40
|
-
SONAR_TOKEN: ${SONAR_TOKEN}
|
|
41
|
-
|
|
42
|
-
caches:
|
|
43
|
-
sonar: /opt/sonar-scanner/.sonar
|
|
44
|
-
|
|
45
|
-
clone:
|
|
46
|
-
depth: full
|
|
47
|
-
|
|
48
|
-
pipelines:
|
|
49
|
-
branches:
|
|
50
|
-
"{main,test,prod}":
|
|
51
|
-
- step: *build-step
|
|
52
|
-
- parallel:
|
|
53
|
-
- step: *format-step
|
|
54
|
-
- step: *lint-step
|
|
55
|
-
- step: *test-step
|
|
56
|
-
- step: *code-analysis-step
|
|
57
|
-
|
|
58
|
-
pull-requests:
|
|
59
|
-
"**":
|
|
60
|
-
- step: *build-step
|
|
61
|
-
- parallel:
|
|
62
|
-
- step: *format-step
|
|
63
|
-
- step: *lint-step
|
|
64
|
-
- step: *test-step
|
|
65
|
-
- step: *code-analysis-step
|
package/jest.config.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* For a detailed explanation regarding each configuration property and type check, visit:
|
|
3
|
-
* https://jestjs.io/docs/en/configuration.html
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
module.exports = {
|
|
7
|
-
/**
|
|
8
|
-
* Paths
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// A list of paths to directories that Jest should use to search for files in
|
|
12
|
-
roots: ["./test"],
|
|
13
|
-
|
|
14
|
-
// The glob patterns Jest uses to detect test files
|
|
15
|
-
testMatch: ["<rootDir>/test/**/*.test.ts"],
|
|
16
|
-
|
|
17
|
-
// Transformers for files
|
|
18
|
-
transform: {
|
|
19
|
-
"^.+\\.tsx?$": [
|
|
20
|
-
"esbuild-jest",
|
|
21
|
-
{
|
|
22
|
-
sourcemap: true,
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
/*
|
|
28
|
-
* Results processing
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
// Indicates whether the coverage information should be collected while executing the test
|
|
32
|
-
collectCoverage: true,
|
|
33
|
-
|
|
34
|
-
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
35
|
-
collectCoverageFrom: ["src/**/*.ts"],
|
|
36
|
-
|
|
37
|
-
// An array of regexp pattern strings used to skip coverage for certain files
|
|
38
|
-
coveragePathIgnorePatterns: ["src/logger.ts"],
|
|
39
|
-
|
|
40
|
-
// The directory where Jest should output its coverage files
|
|
41
|
-
coverageDirectory: ".coverage",
|
|
42
|
-
|
|
43
|
-
// Export test results fo SonarQube scanner to process test results
|
|
44
|
-
testResultsProcessor: "jest-sonar-reporter",
|
|
45
|
-
|
|
46
|
-
/*
|
|
47
|
-
* Test environment
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
// The test environment that will be used for testing
|
|
51
|
-
testEnvironment: "node",
|
|
52
|
-
|
|
53
|
-
// Run for all tests
|
|
54
|
-
// setupFiles: ["<rootDir>/test/env.ts"],
|
|
55
|
-
|
|
56
|
-
/*
|
|
57
|
-
* Mocks
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
// Automatically clear mock calls and instances between every test
|
|
61
|
-
clearMocks: true,
|
|
62
|
-
}
|
package/sonar-project.properties
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
sonar.projectKey=tomassaboldev_aws-services_bb5f4f68-64f8-4726-bdd4-579ceadf172d
|
|
2
|
-
sonar.sources=src
|
|
3
|
-
sonar.tests=test
|
|
4
|
-
sonar.exclusions=src/logger.ts
|
|
5
|
-
sonar.scm.provider=git
|
|
6
|
-
sonar.qualitygate.wait=true
|
|
7
|
-
sonar.javascript.lcov.reportPaths=.coverage/lcov.info
|
|
8
|
-
sonar.testExecutionReportPaths=.sonar/test-report.xml
|
package/src/appconfig.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AppConfigClient,
|
|
3
|
-
GetApplicationCommand,
|
|
4
|
-
} from "@aws-sdk/client-appconfig"
|
|
5
|
-
import { logger } from "./logger"
|
|
6
|
-
|
|
7
|
-
export const appConfigClient = new AppConfigClient({})
|
|
8
|
-
|
|
9
|
-
export const getApplication = async (applicationId: string) => {
|
|
10
|
-
try {
|
|
11
|
-
return await appConfigClient.send(
|
|
12
|
-
new GetApplicationCommand({
|
|
13
|
-
ApplicationId: applicationId,
|
|
14
|
-
})
|
|
15
|
-
)
|
|
16
|
-
} catch (error) {
|
|
17
|
-
logger.error("getApplication", { error, applicationId })
|
|
18
|
-
throw error
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/dynamodb.mock.ts
DELETED
package/src/dynamodb.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"
|
|
2
|
-
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"
|
|
3
|
-
|
|
4
|
-
export const client: DynamoDBClient = new DynamoDBClient({})
|
|
5
|
-
|
|
6
|
-
export const documentClient: DynamoDBDocumentClient =
|
|
7
|
-
DynamoDBDocumentClient.from(client)
|
package/src/eventbridge.mock.ts
DELETED
package/src/eventbridge.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import {
|
|
3
|
-
EventBridgeClient,
|
|
4
|
-
PutEventsCommand,
|
|
5
|
-
} from "@aws-sdk/client-eventbridge"
|
|
6
|
-
import { logger } from "./logger"
|
|
7
|
-
|
|
8
|
-
export const client = new EventBridgeClient({})
|
|
9
|
-
|
|
10
|
-
export async function sendEvent(params: {
|
|
11
|
-
source: string
|
|
12
|
-
eventBusName: string
|
|
13
|
-
eventType: string
|
|
14
|
-
event: any
|
|
15
|
-
}) {
|
|
16
|
-
const { eventBusName, eventType, event, source } = params
|
|
17
|
-
|
|
18
|
-
const input = {
|
|
19
|
-
Entries: [
|
|
20
|
-
{
|
|
21
|
-
EventBusName: eventBusName,
|
|
22
|
-
Source: source,
|
|
23
|
-
DetailType: eventType,
|
|
24
|
-
Detail: JSON.stringify(event),
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const command = new PutEventsCommand(input)
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
const result = await client.send(command)
|
|
33
|
-
|
|
34
|
-
/* Check if there are any failed events */
|
|
35
|
-
if (result.FailedEntryCount) {
|
|
36
|
-
const errorDetail = result.Entries?.length
|
|
37
|
-
? `${result.Entries[0].ErrorCode}: ${result.Entries[0].ErrorMessage}}`
|
|
38
|
-
: "unknown"
|
|
39
|
-
throw new Error(`PutEventsCommand error ${errorDetail}`)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
logger.debug("sendEvent success", { input, result })
|
|
43
|
-
} catch (error) {
|
|
44
|
-
logger.error("sendEvent error", { input, error })
|
|
45
|
-
throw error
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/logger.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Logger } from "@aws-lambda-powertools/logger"
|
|
2
|
-
|
|
3
|
-
const noLogger = {
|
|
4
|
-
log: () => undefined,
|
|
5
|
-
debug: () => undefined,
|
|
6
|
-
info: () => undefined,
|
|
7
|
-
error: () => undefined,
|
|
8
|
-
warn: () => undefined,
|
|
9
|
-
} as typeof console
|
|
10
|
-
|
|
11
|
-
export const logger =
|
|
12
|
-
process.env.JEST_WORKER_ID === undefined || process.env.TEST_LOGGER
|
|
13
|
-
? new Logger({ logLevel: "DEBUG" })
|
|
14
|
-
: noLogger
|
package/src/s3.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { S3, PutObjectCommandOutput } from "@aws-sdk/client-s3"
|
|
2
|
-
import { logger } from "./logger"
|
|
3
|
-
|
|
4
|
-
export const client = new S3({})
|
|
5
|
-
|
|
6
|
-
export async function putObjectToS3(params: {
|
|
7
|
-
bucket: string
|
|
8
|
-
key: string
|
|
9
|
-
body: string | Uint8Array | Buffer
|
|
10
|
-
contentEncoding: string
|
|
11
|
-
contentType: string
|
|
12
|
-
}): Promise<PutObjectCommandOutput> {
|
|
13
|
-
const { bucket, key, body, contentEncoding, contentType } = params
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
return await client.putObject({
|
|
17
|
-
Bucket: bucket,
|
|
18
|
-
Key: key,
|
|
19
|
-
Body: body,
|
|
20
|
-
ContentEncoding: contentEncoding,
|
|
21
|
-
ContentType: contentType,
|
|
22
|
-
})
|
|
23
|
-
} catch (error) {
|
|
24
|
-
logger.error("putObjectToS3", {
|
|
25
|
-
error,
|
|
26
|
-
params: { bucket, key, contentEncoding, contentType },
|
|
27
|
-
})
|
|
28
|
-
throw error
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function getObjectFromS3(params: {
|
|
33
|
-
bucket: string
|
|
34
|
-
key: string
|
|
35
|
-
}): Promise<Uint8Array> {
|
|
36
|
-
try {
|
|
37
|
-
const { bucket, key } = params
|
|
38
|
-
|
|
39
|
-
const result = await client.getObject({
|
|
40
|
-
Bucket: bucket,
|
|
41
|
-
Key: key,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const body = result.Body
|
|
45
|
-
|
|
46
|
-
if (body === undefined) {
|
|
47
|
-
logger.error("Body not found", { params })
|
|
48
|
-
throw new Error("Body not found")
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return await body.transformToByteArray()
|
|
52
|
-
} catch (error) {
|
|
53
|
-
logger.error("getObjectFromS3", { error, params })
|
|
54
|
-
throw error
|
|
55
|
-
}
|
|
56
|
-
}
|
package/src/secrets-manager.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SecretsManagerClient,
|
|
3
|
-
GetSecretValueCommand,
|
|
4
|
-
} from "@aws-sdk/client-secrets-manager"
|
|
5
|
-
import assert from "assert"
|
|
6
|
-
import { logger } from "./logger"
|
|
7
|
-
|
|
8
|
-
export const client = new SecretsManagerClient({})
|
|
9
|
-
|
|
10
|
-
export async function getSecret(secretName: string): Promise<string> {
|
|
11
|
-
try {
|
|
12
|
-
const response = await client.send(
|
|
13
|
-
new GetSecretValueCommand({
|
|
14
|
-
SecretId: secretName,
|
|
15
|
-
})
|
|
16
|
-
)
|
|
17
|
-
const value = response.SecretString
|
|
18
|
-
assert(value, "SecretString value not found")
|
|
19
|
-
return value
|
|
20
|
-
} catch (error) {
|
|
21
|
-
logger.error("getSecret", { error, secretName })
|
|
22
|
-
// For a list of exceptions thrown, see
|
|
23
|
-
// https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
|
|
24
|
-
throw error
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function getSecretAsObject<T = unknown>(
|
|
29
|
-
secretName: string
|
|
30
|
-
): Promise<T> {
|
|
31
|
-
const value = await getSecret(secretName)
|
|
32
|
-
try {
|
|
33
|
-
return JSON.parse(value)
|
|
34
|
-
} catch (error) {
|
|
35
|
-
throw Error(`Cannot parse secret ${secretName}. Expected JSON.`)
|
|
36
|
-
}
|
|
37
|
-
}
|
package/src/sns.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { SNSClient, PublishCommand } from "@aws-sdk/client-sns"
|
|
2
|
-
import { logger } from "./logger"
|
|
3
|
-
|
|
4
|
-
export const snsClient = new SNSClient({})
|
|
5
|
-
|
|
6
|
-
export const publishMessageToSNS = async (params: {
|
|
7
|
-
topicArn: string
|
|
8
|
-
message: string
|
|
9
|
-
options?: object
|
|
10
|
-
}) => {
|
|
11
|
-
try {
|
|
12
|
-
const { topicArn, message, options } = params
|
|
13
|
-
return await snsClient.send(
|
|
14
|
-
new PublishCommand({
|
|
15
|
-
TopicArn: topicArn,
|
|
16
|
-
Message: message,
|
|
17
|
-
...options,
|
|
18
|
-
})
|
|
19
|
-
)
|
|
20
|
-
} catch (error) {
|
|
21
|
-
logger.error("publishMessageToSNS", { error, params })
|
|
22
|
-
throw error
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/sqs.mock.ts
DELETED
package/src/sqs.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SQSClient,
|
|
3
|
-
SendMessageCommand,
|
|
4
|
-
SendMessageCommandInput,
|
|
5
|
-
} from "@aws-sdk/client-sqs"
|
|
6
|
-
import { logger } from "./logger"
|
|
7
|
-
|
|
8
|
-
export const client = new SQSClient({})
|
|
9
|
-
|
|
10
|
-
export async function sendSqsMessage(params: {
|
|
11
|
-
queueUrl: string
|
|
12
|
-
message: string | object
|
|
13
|
-
}): Promise<string | undefined> {
|
|
14
|
-
const { queueUrl, message } = params
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
const body = typeof message === "object" ? JSON.stringify(message) : message
|
|
18
|
-
|
|
19
|
-
const input: SendMessageCommandInput = {
|
|
20
|
-
QueueUrl: queueUrl,
|
|
21
|
-
MessageBody: body,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const command = new SendMessageCommand(input)
|
|
25
|
-
|
|
26
|
-
const response = await client.send(command)
|
|
27
|
-
return response.MessageId
|
|
28
|
-
} catch (error) {
|
|
29
|
-
logger.error("sendSqsMessage", { error, params })
|
|
30
|
-
throw error
|
|
31
|
-
}
|
|
32
|
-
}
|
package/src/ssm.mock.ts
DELETED
package/src/ssm.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { SSMClient, GetParametersCommand } from "@aws-sdk/client-ssm"
|
|
2
|
-
import assert = require("assert")
|
|
3
|
-
|
|
4
|
-
export const client = new SSMClient({})
|
|
5
|
-
|
|
6
|
-
export type SSMParameters = {
|
|
7
|
-
[name: string]: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get a list of parameters from SSM Parameter Store
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const params = await getSsmParameters({
|
|
16
|
-
* first: "/my-params/first",
|
|
17
|
-
* second: "/my-params/second",
|
|
18
|
-
* })
|
|
19
|
-
*
|
|
20
|
-
* // params = { first: "value1", second: "value2" }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
export async function getSsmParameters<T extends SSMParameters>(
|
|
25
|
-
parameters: T
|
|
26
|
-
): Promise<T> {
|
|
27
|
-
/*
|
|
28
|
-
* Fetch parameters from SSM
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
const command = new GetParametersCommand({
|
|
32
|
-
Names: Object.values(parameters),
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const output = await client.send(command)
|
|
36
|
-
|
|
37
|
-
/*
|
|
38
|
-
* Map returned parameters to result object
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
const result: Record<string, string> = {}
|
|
42
|
-
output.Parameters?.forEach((outputParam) => {
|
|
43
|
-
assert(
|
|
44
|
-
typeof outputParam.Value === "string",
|
|
45
|
-
`Received invalid value of SSM parameter ${outputParam.Name}`
|
|
46
|
-
)
|
|
47
|
-
const entry = Object.entries(parameters).find(
|
|
48
|
-
([_key, value]) => value === outputParam.Name
|
|
49
|
-
)
|
|
50
|
-
assert(entry, `Received invalid SSM parameter ${outputParam.Name}`)
|
|
51
|
-
const [key] = entry
|
|
52
|
-
result[key] = outputParam.Value
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
/*
|
|
56
|
-
* Check that all parameters were received
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
const notFoundParams = Object.keys(parameters).filter(
|
|
60
|
-
(key) => false === Object.hasOwn(result, key)
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
if (notFoundParams.length > 0) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`Cannot obtain SSM parameters: ${notFoundParams.join(", ")}`
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return result as T
|
|
70
|
-
}
|
package/test/appconfig.test.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { GetApplicationCommand } from "@aws-sdk/client-appconfig"
|
|
2
|
-
import { getApplication, appConfigClient } from "../src/appconfig"
|
|
3
|
-
|
|
4
|
-
jest.mock("@aws-sdk/client-appconfig", () => {
|
|
5
|
-
return {
|
|
6
|
-
AppConfigClient: jest.fn().mockImplementation(() => {
|
|
7
|
-
return { send: jest.fn() }
|
|
8
|
-
}),
|
|
9
|
-
GetApplicationCommand: jest.fn(),
|
|
10
|
-
}
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
describe("AppConfig", () => {
|
|
14
|
-
let getApplicationCommandMock: jest.Mock
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
getApplicationCommandMock = GetApplicationCommand as unknown as jest.Mock
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
jest.clearAllMocks()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it("should call AppConfig.getApplication with correct parameters", async () => {
|
|
25
|
-
const applicationId = "test-app"
|
|
26
|
-
|
|
27
|
-
await getApplication(applicationId)
|
|
28
|
-
|
|
29
|
-
expect(appConfigClient.send).toHaveBeenCalledWith(
|
|
30
|
-
expect.any(getApplicationCommandMock)
|
|
31
|
-
)
|
|
32
|
-
expect(getApplicationCommandMock).toHaveBeenCalledWith({
|
|
33
|
-
ApplicationId: applicationId,
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it("should throw an error if getting application from AppConfig fails", async () => {
|
|
38
|
-
const applicationId = "test-app"
|
|
39
|
-
const error = new Error("Get application failed")
|
|
40
|
-
|
|
41
|
-
;(appConfigClient.send as jest.Mock).mockRejectedValueOnce(error)
|
|
42
|
-
|
|
43
|
-
await expect(getApplication(applicationId)).rejects.toThrow(error)
|
|
44
|
-
})
|
|
45
|
-
})
|
package/test/dynamodb.test.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { client, documentClient } from "../src/dynamodb"
|
|
2
|
-
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"
|
|
3
|
-
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"
|
|
4
|
-
|
|
5
|
-
describe("dynamodb", () => {
|
|
6
|
-
it("should be instance of DynamoDBClient", () => {
|
|
7
|
-
expect(client).toBeInstanceOf(DynamoDBClient)
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it("should be instance of DynamoDBDocumentClient", () => {
|
|
11
|
-
expect(documentClient).toBeInstanceOf(DynamoDBDocumentClient)
|
|
12
|
-
})
|
|
13
|
-
})
|
package/test/eventbridge.test.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { mockClient } from "aws-sdk-client-mock"
|
|
2
|
-
import { PutEventsCommand } from "@aws-sdk/client-eventbridge"
|
|
3
|
-
import { client, sendEvent } from "../src/eventbridge"
|
|
4
|
-
|
|
5
|
-
const eventBridgeMock = mockClient(client)
|
|
6
|
-
|
|
7
|
-
describe("eventbridge", () => {
|
|
8
|
-
describe("sendEvent", () => {
|
|
9
|
-
test("should send event to event bus", async () => {
|
|
10
|
-
eventBridgeMock.on(PutEventsCommand).resolves({})
|
|
11
|
-
|
|
12
|
-
const params = {
|
|
13
|
-
source: "source",
|
|
14
|
-
eventBusName: "event-bus-name",
|
|
15
|
-
eventType: "event-type",
|
|
16
|
-
event: { foo: "bar" },
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
await expect(sendEvent(params)).resolves.toBe(undefined)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
test("should fail", async () => {
|
|
23
|
-
eventBridgeMock.on(PutEventsCommand).rejects(new Error("fail"))
|
|
24
|
-
|
|
25
|
-
const params = {
|
|
26
|
-
source: "source",
|
|
27
|
-
eventBusName: "event-bus-name",
|
|
28
|
-
eventType: "event-type",
|
|
29
|
-
event: { foo: "bar" },
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
await expect(sendEvent(params)).rejects.toThrowError("fail")
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
})
|