Skip to content

Commit 8ca2c01

Browse files
author
Phil Varner
authored
remove aws-sdk usage (#650)
* remove aws-sdk usage * fix type problems * opensearch 2.11 in ci * use localstack 3 * changelog
1 parent 2716bcf commit 8ca2c01

File tree

10 files changed

+27
-29
lines changed

10 files changed

+27
-29
lines changed

.github/workflows/push.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
services:
1616
localstack:
17-
image: localstack/localstack
17+
image: localstack/localstack:3
1818
env:
1919
SERVICES: s3,sns,sqs
2020
ports:
@@ -28,7 +28,7 @@ jobs:
2828
cache-dependency-path: package.json
2929
- uses: ankane/setup-opensearch@v1
3030
with:
31-
opensearch-version: 2.7
31+
opensearch-version: 2.11
3232
- name: Upgrade npm
3333
run: npm install -g npm@8.19.4
3434
- name: Install dependencies

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased] - TBD
9+
10+
### Added
11+
12+
- Better error handling when create_index fails.
13+
14+
### Fixed
15+
16+
- Removed usages of aws-sdk that were missed in 3.0.0.
17+
818
## [3.1.0] - 2023-11-28
919

1020
### Added
@@ -386,7 +396,7 @@ Initial release, forked from [sat-api](https://github.com/sat-utils/sat-api/tree
386396

387397
Compliant with STAC 0.9.0
388398

389-
<!-- [Unreleased]: https://github.com/stac-utils/stac-api/compare/v2.4.0...main -->
399+
[Unreleased]: https://github.com/stac-utils/stac-api/compare/v2.4.0...main
390400
[3.1.0]: https://github.com/stac-utils/stac-api/compare/v3.0.0...v3.1.0
391401
[3.0.0]: https://github.com/stac-utils/stac-api/compare/v2.4.0...v3.0.0
392402
[2.4.0]: https://github.com/stac-utils/stac-api/compare/v2.3.0...v2.4.0

docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ services:
88
volumes:
99
- ./opensearch/config/opensearch.yml:/usr/share/opensearch/config/opensearch.yml
1010
localstack:
11-
image: localstack/localstack:2.1.0
11+
image: localstack/localstack:3
1212
ports:
13-
- "127.0.0.1:4566:4566"
13+
- "127.0.0.1:4566:4566" # LocalStack Gateway
14+
- "127.0.0.1:4510-4559:4510-4559" # external services port range
1415
environment:
1516
- SERVICES=s3,sns,sqs

src/lambdas/api/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { z } from 'zod'
1010
import serverless from 'serverless-http'
11-
import { Lambda } from 'aws-sdk'
11+
import { Lambda } from '@aws-sdk/client-lambda'
1212
import { app } from './app.js'
1313
import _default from './types.js'
1414
import logger from '../../lib/logger.js'
@@ -70,20 +70,20 @@ const logZodParseError = (data, error) => {
7070
* @returns {Promise<APIGatewayProxyEvent|APIGatewayProxyResult>}
7171
*/
7272
const invokePreHook = async (lambda, preHook, payload) => {
73-
/** @type {Lambda.InvocationResponse} */
73+
/** @type {import("@aws-sdk/client-lambda").InvocationResponse} */
7474
let invocationResponse
7575
try {
7676
invocationResponse = await lambda.invoke({
7777
FunctionName: preHook,
7878
Payload: JSON.stringify(payload)
79-
}).promise()
79+
})
8080
} catch (error) {
8181
logger.error('Failed to invoke pre-hook lambda:', error)
8282
return internalServerError
8383
}
8484

8585
// I've never seen this happen but, according to the TypeScript type definitions
86-
// provided by AWS, `Lambda.InvocationResponse.Payload` could be `undefined`.
86+
// provided by AWS, `InvocationResponse.Payload` could be `undefined`.
8787
if (invocationResponse.Payload === undefined) {
8888
logger.error('Undefined Payload returned from pre-hook lambda')
8989
return internalServerError
@@ -117,20 +117,20 @@ const invokePreHook = async (lambda, preHook, payload) => {
117117
* @returns {Promise<APIGatewayProxyResult>}
118118
*/
119119
const invokePostHook = async (lambda, postHook, payload) => {
120-
/** @type {Lambda.InvocationResponse} */
120+
/** @type {import("@aws-sdk/client-lambda").InvocationResponse} */
121121
let invocationResponse
122122
try {
123123
invocationResponse = await lambda.invoke({
124124
FunctionName: postHook,
125125
Payload: JSON.stringify(payload)
126-
}).promise()
126+
})
127127
} catch (error) {
128128
logger.error('Failed to invoke post-hook lambda:', error)
129129
return internalServerError
130130
}
131131

132132
// I've never seen this happen but, according to the TypeScript type definitions
133-
// provided by AWS, `Lambda.InvocationResponse.Payload` could be `undefined`.
133+
// provided by AWS, `InvocationResponse.Payload` could be `undefined`.
134134
if (invocationResponse.Payload === undefined) {
135135
logger.error('Undefined Payload returned from post-hook lambda')
136136
return internalServerError

src/lambdas/api/webpack.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ export default {
2020
filename: 'index.js',
2121
path: resolve(__dirname, '..', '..', '..', 'dist', 'api')
2222
},
23-
externals: [
24-
'aws-sdk'
25-
],
2623
devtool,
2724
resolve: {
2825
extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"],

src/lambdas/ingest/webpack.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ export default {
1919
filename: 'index.js',
2020
path: resolve(__dirname, '..', '..', '..', 'dist', 'ingest')
2121
},
22-
externals: [
23-
'aws-sdk'
24-
],
2522
devtool,
2623
resolve: {
2724
extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"],

src/lambdas/post-hook/webpack.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ export default {
1919
filename: 'index.js',
2020
path: resolve(__dirname, '..', '..', '..', 'dist', 'post-hook')
2121
},
22-
externals: [
23-
'aws-sdk'
24-
],
2522
devtool,
2623
resolve: {
2724
extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"],

src/lambdas/pre-hook/webpack.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ export default {
1919
filename: 'index.js',
2020
path: resolve(__dirname, '..', '..', '..', 'dist', 'pre-hook')
2121
},
22-
externals: [
23-
'aws-sdk'
24-
],
2522
devtool,
2623
resolve: {
2724
extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"],

src/lib/database-client.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ export async function createIndex(index) {
8686
logger.info(`Created index ${index}`)
8787
logger.debug('Mapping: %j', indexConfiguration)
8888
} catch (error) {
89-
logger.debug(`Error creating index '${index}'`, error)
89+
logger.error(`Error creating index '${index}'`, error)
90+
throw error
9091
}
92+
} else {
93+
logger.error(`${index} already exists.`)
9194
}
9295
}

tests/unit/test-ingest-1.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ const setup = () => {
1212
promise: () => (Promise.resolve(true))
1313
})
1414
ECS.prototype.runTask = runTask
15-
const AWS = {
16-
ECS
17-
}
1815
const lambda = proxyquire('../../src/lambdas/ingest/', {
19-
'aws-sdk': AWS
2016
})
2117
return {
2218
ingest,

0 commit comments

Comments
 (0)