Skip to content

Commit bcdb04f

Browse files
committed
feat(v1): first version
1 parent 8dfaadc commit bcdb04f

File tree

6 files changed

+237
-0
lines changed

6 files changed

+237
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.md]
11+
max_line_length = off
12+
trim_trailing_whitespace = false

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ jspm_packages
3535

3636
# Optional REPL history
3737
.node_repl_history
38+
39+
.DS_Store

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v4.3.2

index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict'
2+
3+
const AWS = require('aws-sdk')
4+
const elasticsearch = require('elasticsearch')
5+
const httpAWSESClass = require('http-aws-es')
6+
7+
// serverless-offline will set IS_OFFLINE based on whether we're offline
8+
const devMode = process.env.IS_OFFLINE === 'true'
9+
10+
function createClient (options) {
11+
const prefix = options.envPrefix || 'AWS'
12+
const region = options.region || process.env[`${prefix}_REGION`]
13+
const host = options.host || process.env[`${prefix}_HOST`]
14+
15+
if (!region) { throw new Error('region is required') }
16+
if (!host) { throw new Error('host is required') }
17+
18+
const credentials = options.credentials || new AWS.EnvironmentCredentials(prefix)
19+
20+
const config = Object.assign({}, options, {
21+
host: host,
22+
amazonES: {
23+
region,
24+
credentials
25+
}
26+
})
27+
28+
// don't sign the request in offline mode
29+
if (!devMode) {
30+
config.connectionClass = httpAWSESClass
31+
}
32+
33+
return new elasticsearch.Client(config)
34+
}
35+
36+
module.exports = createClient

package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "serverless-elasticsearch-client",
3+
"version": "1.0.0",
4+
"description": "Elasticsearch client for AWS that plays nicely with serverless-offline and signed requests",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/goldcaddy77/serverless-elasticsearch-client.git"
12+
},
13+
"keywords": [
14+
"elasticsearch",
15+
"aws",
16+
"serverless",
17+
"serverless-offline"
18+
],
19+
"author": "Dan Caddigan",
20+
"license": "ISC",
21+
"bugs": {
22+
"url": "https://github.com/goldcaddy77/serverless-elasticsearch-client/issues"
23+
},
24+
"homepage": "https://github.com/goldcaddy77/serverless-elasticsearch-client#readme",
25+
"dependencies": {
26+
"aws-sdk": "^2.20.0",
27+
"elasticsearch": "^12.1.3",
28+
"http-aws-es": "^1.1.3"
29+
}
30+
}

yarn.lock

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
ansi-regex@^2.0.0:
6+
version "2.1.1"
7+
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
8+
9+
ansi-styles@^2.2.1:
10+
version "2.2.1"
11+
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
12+
13+
asap@~2.0.3:
14+
version "2.0.5"
15+
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.5.tgz#522765b50c3510490e52d7dcfe085ef9ba96958f"
16+
17+
aws-sdk@^2.2.19, aws-sdk@^2.20.0:
18+
version "2.20.0"
19+
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.20.0.tgz#e083f33a597661bb91e43911a99bb794797e8ca1"
20+
dependencies:
21+
buffer "4.9.1"
22+
crypto-browserify "1.0.9"
23+
jmespath "0.15.0"
24+
querystring "0.2.0"
25+
sax "1.1.5"
26+
url "0.10.3"
27+
uuid "3.0.0"
28+
xml2js "0.4.15"
29+
xmlbuilder "2.6.2"
30+
31+
base64-js@^1.0.2:
32+
version "1.2.0"
33+
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.0.tgz#a39992d723584811982be5e290bb6a53d86700f1"
34+
35+
buffer@4.9.1:
36+
version "4.9.1"
37+
resolved "https://registry.yarnpkg.com/buffer/-/buffer-4.9.1.tgz#6d1bb601b07a4efced97094132093027c95bc298"
38+
dependencies:
39+
base64-js "^1.0.2"
40+
ieee754 "^1.1.4"
41+
isarray "^1.0.0"
42+
43+
chalk@^1.0.0:
44+
version "1.1.3"
45+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
46+
dependencies:
47+
ansi-styles "^2.2.1"
48+
escape-string-regexp "^1.0.2"
49+
has-ansi "^2.0.0"
50+
strip-ansi "^3.0.0"
51+
supports-color "^2.0.0"
52+
53+
crypto-browserify@1.0.9:
54+
version "1.0.9"
55+
resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-1.0.9.tgz#cc5449685dfb85eb11c9828acc7cb87ab5bbfcc0"
56+
57+
elasticsearch@^12.1.3:
58+
version "12.1.3"
59+
resolved "https://registry.yarnpkg.com/elasticsearch/-/elasticsearch-12.1.3.tgz#5108e67ae5d83e5e7f30d3d294fd7017df0e3771"
60+
dependencies:
61+
chalk "^1.0.0"
62+
forever-agent "^0.6.0"
63+
lodash "^4.12.0"
64+
promise "^7.1.1"
65+
66+
escape-string-regexp@^1.0.2:
67+
version "1.0.5"
68+
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
69+
70+
forever-agent@^0.6.0:
71+
version "0.6.1"
72+
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
73+
74+
has-ansi@^2.0.0:
75+
version "2.0.0"
76+
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
77+
dependencies:
78+
ansi-regex "^2.0.0"
79+
80+
http-aws-es@^1.1.3:
81+
version "1.1.3"
82+
resolved "https://registry.yarnpkg.com/http-aws-es/-/http-aws-es-1.1.3.tgz#64951843b5c511305072570d7c2c509f78144d6b"
83+
dependencies:
84+
aws-sdk "^2.2.19"
85+
86+
ieee754@^1.1.4:
87+
version "1.1.8"
88+
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4"
89+
90+
isarray@^1.0.0:
91+
version "1.0.0"
92+
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
93+
94+
jmespath@0.15.0:
95+
version "0.15.0"
96+
resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.15.0.tgz#a3f222a9aae9f966f5d27c796510e28091764217"
97+
98+
lodash@^4.12.0:
99+
version "4.17.4"
100+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
101+
102+
lodash@~3.5.0:
103+
version "3.5.0"
104+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.5.0.tgz#19bb3f4d51278f0b8c818ed145c74ecf9fe40e6d"
105+
106+
promise@^7.1.1:
107+
version "7.1.1"
108+
resolved "https://registry.yarnpkg.com/promise/-/promise-7.1.1.tgz#489654c692616b8aa55b0724fa809bb7db49c5bf"
109+
dependencies:
110+
asap "~2.0.3"
111+
112+
punycode@1.3.2:
113+
version "1.3.2"
114+
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d"
115+
116+
querystring@0.2.0:
117+
version "0.2.0"
118+
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
119+
120+
sax@1.1.5, sax@>=0.6.0:
121+
version "1.1.5"
122+
resolved "https://registry.yarnpkg.com/sax/-/sax-1.1.5.tgz#1da50a8d00cdecd59405659f5ff85349fe773743"
123+
124+
strip-ansi@^3.0.0:
125+
version "3.0.1"
126+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"
127+
dependencies:
128+
ansi-regex "^2.0.0"
129+
130+
supports-color@^2.0.0:
131+
version "2.0.0"
132+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
133+
134+
url@0.10.3:
135+
version "0.10.3"
136+
resolved "https://registry.yarnpkg.com/url/-/url-0.10.3.tgz#021e4d9c7705f21bbf37d03ceb58767402774c64"
137+
dependencies:
138+
punycode "1.3.2"
139+
querystring "0.2.0"
140+
141+
uuid@3.0.0:
142+
version "3.0.0"
143+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.0.tgz#6728fc0459c450d796a99c31837569bdf672d728"
144+
145+
xml2js@0.4.15:
146+
version "0.4.15"
147+
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.15.tgz#95cd03ff2dd144ec28bc6273bf2b2890c581ad0c"
148+
dependencies:
149+
sax ">=0.6.0"
150+
xmlbuilder ">=2.4.6"
151+
152+
xmlbuilder@2.6.2, xmlbuilder@>=2.4.6:
153+
version "2.6.2"
154+
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-2.6.2.tgz#f916f6d10d45dc171b1be2e6e673fb6e0cc35d0a"
155+
dependencies:
156+
lodash "~3.5.0"

0 commit comments

Comments
 (0)