-
Notifications
You must be signed in to change notification settings - Fork 1.8k
test(NODE-4160): add aws lambda examples #3369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e81d30c
test(NODE-4160): add aws lambda examples
durran c2362de
test(NODE-4160): add evg run for lambda example
durran 71906f5
test(NODE-4160): update test readme
durran 1bcd70f
Revert "test: adjust number of iterations of flakey test"
baileympearson 866cecd
test(NODE-4160): address comments
durran 02f0a8b
chore(NODE-4160): move to other examples
durran 3a7e684
test(NODE-4160): grep out the aws lambda tests
durran 0346341
test(NODE-4160): ignore aws tests in config
durran 05ff7fd
Update test/readme.md
durran 0e8a444
test(NODE-4160): change server to rapid
durran 30ecb53
test(NODE-4160): add build variants
durran b5f5d2a
test(NODE-4160): pass options to client
durran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
# set -o xtrace # Write all commands first to stderr | ||
set -o errexit # Exit the script with error if any of the commands fail | ||
|
||
MONGODB_URI=${MONGODB_URI:-} | ||
|
||
# ensure no secrets are printed in log files | ||
set +x | ||
|
||
# load node.js environment | ||
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" | ||
|
||
# the default connection string, may be overridden by the environment script | ||
export MONGODB_URI="mongodb://localhost:27017/aws" | ||
|
||
# load the script | ||
shopt -s expand_aliases # needed for `urlencode` alias | ||
[ -s "$PROJECT_DIRECTORY/prepare_mongodb_aws.sh" ] && source "$PROJECT_DIRECTORY/prepare_mongodb_aws.sh" | ||
|
||
# revert to show test output | ||
set -x | ||
|
||
npm install aws4 | ||
npm run check:lambda:aws |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
# set -o xtrace # Write all commands first to stderr | ||
set -o errexit # Exit the script with error if any of the commands fail | ||
|
||
MONGODB_URI=${MONGODB_URI:-} | ||
|
||
# ensure no secrets are printed in log files | ||
set +x | ||
|
||
# load node.js environment | ||
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" | ||
|
||
npm run check:lambda |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// begin lambda connection | ||
const { MongoClient } = require('mongodb'); | ||
|
||
// Get the URI for the cluster then set AWS_ACCESS_KEY_ID as the username in the | ||
// URI and AWS_SECRET_ACCESS_KEY as the password, then set the appropriate auth | ||
// options. Note that MongoClient now auto-connects so no need to store the connect() | ||
// promise anywhere and reference it. | ||
const client = new MongoClient(process.env.MONGODB_URI, { | ||
auth: { | ||
username: process.env.AWS_ACCESS_KEY_ID, | ||
password: process.env.AWS_SECRET_ACCESS_KEY | ||
}, | ||
authSource: '$external', | ||
authMechanism: 'MONGODB-AWS' | ||
}); | ||
|
||
module.exports.handler = async function () { | ||
const databases = await client.db('admin').command({ listDatabases: 1 }); | ||
return { | ||
statusCode: 200, | ||
databases: databases | ||
}; | ||
}; | ||
// end lambda connection | ||
|
||
module.exports.client = client; |
26 changes: 26 additions & 0 deletions
26
test/integration/node-specific/examples/aws_handler.test.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { expect } = require('chai'); | ||
const { client, handler } = require('./aws_handler'); | ||
|
||
describe('AWS Lambda Examples', function () { | ||
describe('#handler', function () { | ||
context('when using aws environment variable authentication', function () { | ||
let response; | ||
|
||
before(async function () { | ||
response = await handler(); | ||
}); | ||
|
||
after(async function () { | ||
await client.close(); | ||
}); | ||
|
||
it('returns the databases', async function () { | ||
expect(response.databases).to.exist; | ||
}); | ||
|
||
it('returns the status code', async function () { | ||
expect(response.statusCode).to.equal(200); | ||
}); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// begin lambda connection | ||
const { MongoClient } = require('mongodb'); | ||
|
||
// MongoClient now auto-connects so no need to store the connect() | ||
// promise anywhere and reference it. | ||
const client = new MongoClient(process.env.MONGODB_URI); | ||
|
||
module.exports.handler = async function () { | ||
const databases = await client.db('admin').command({ listDatabases: 1 }); | ||
return { | ||
statusCode: 200, | ||
databases: databases | ||
}; | ||
}; | ||
// end lambda connection | ||
|
||
module.exports.client = client; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { expect } = require('chai'); | ||
const { client, handler } = require('./handler'); | ||
|
||
describe('AWS Lambda Examples', function () { | ||
describe('#handler', function () { | ||
context('when using standard authentication', function () { | ||
let response; | ||
|
||
before(async function () { | ||
response = await handler(); | ||
}); | ||
|
||
after(async function () { | ||
await client.close(); | ||
}); | ||
|
||
it('returns the databases', async function () { | ||
expect(response.databases).to.exist; | ||
}); | ||
|
||
it('returns the status code', async function () { | ||
expect(response.statusCode).to.equal(200); | ||
}); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const path = require('path'); | ||
const Module = require('module'); | ||
|
||
const loader = Module._load; | ||
|
||
// This little hack is to make require('mongodb') in our own project | ||
// during this specific test run to resolve to /lib so we can do | ||
// const { MongoClient } = require('mongodb'); | ||
Module._load = function (request) { | ||
if (request === 'mongodb') { | ||
arguments[0] = path.join(__dirname, '..', '..', '..', '..', 'lib'); | ||
} | ||
return loader.apply(this, arguments); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/mocharc.json", | ||
"require": [ | ||
"test/integration/node-specific/examples/setup.js" | ||
], | ||
"extension": ["js"], | ||
"ui": "test/tools/runner/metadata_ui.js", | ||
"recursive": true, | ||
"timeout": 6000, | ||
"failZero": true, | ||
"reporter": "test/tools/reporter/mongodb_reporter.js", | ||
"sort": true, | ||
"color": true | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.