-
Notifications
You must be signed in to change notification settings - Fork 534
RUBY-3149 Test on AWS Lambda #2800
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
8 commits
Select commit
Hold shift + click to select a range
28a70f0
Bump drivers tools
comandeo-mongo 3b73bfa
Implement lambda
comandeo-mongo 1d979ff
Add evergreen config
comandeo-mongo 0b8a747
Make it work
comandeo-mongo ce2bb74
Fix code review remarks
comandeo-mongo 5d78c84
Rearrange env variables
comandeo-mongo 587d507
Try to satisfy evergreen
comandeo-mongo b3d4fcc
Revert some changes in evg setup
comandeo-mongo 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 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 @@ | ||
../.mod/drivers-evergreen-tools/.evergreen/atlas |
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
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,117 @@ | ||
#!/bin/bash | ||
set -o errexit # Exit the script with error if any of the commands fail | ||
|
||
# Explanation of required environment variables: | ||
# | ||
# TEST_LAMBDA_DIRECTORY: The root of the project's Lambda sam project. | ||
# DRIVERS_ATLAS_PUBLIC_API_KEY: The public Atlas key for the drivers org. | ||
# DRIVERS_ATLAS_PRIVATE_API_KEY: The private Atlas key for the drivers org. | ||
# DRIVERS_ATLAS_LAMBDA_USER: The user for the lambda cluster. | ||
# DRIVERS_ATLAS_LAMBDA_PASSWORD: The password for the user. | ||
# DRIVERS_ATLAS_GROUP_ID: The id of the individual projects under the drivers org, per language. | ||
# LAMBDA_STACK_NAME: The name of the stack on lambda "dbx-<language>-lambda" | ||
# AWS_REGION: The region for the function - generally us-east-1 | ||
|
||
VARLIST=( | ||
TEST_LAMBDA_DIRECTORY | ||
DRIVERS_ATLAS_PUBLIC_API_KEY | ||
DRIVERS_ATLAS_PRIVATE_API_KEY | ||
DRIVERS_ATLAS_LAMBDA_USER | ||
DRIVERS_ATLAS_LAMBDA_PASSWORD | ||
DRIVERS_ATLAS_GROUP_ID | ||
LAMBDA_STACK_NAME | ||
AWS_REGION | ||
) | ||
|
||
# Ensure that all variables required to run the test are set, otherwise throw | ||
# an error. | ||
for VARNAME in ${VARLIST[*]}; do | ||
[[ -z "${!VARNAME}" ]] && echo "ERROR: $VARNAME not set" && exit 1; | ||
done | ||
|
||
# Set up the common variables | ||
. `dirname "$0"`/atlas/setup-variables.sh | ||
|
||
# Restarts the cluster's primary node. | ||
restart_cluster_primary () | ||
{ | ||
echo "Testing Atlas primary restart..." | ||
curl \ | ||
--digest -u ${DRIVERS_ATLAS_PUBLIC_API_KEY}:${DRIVERS_ATLAS_PRIVATE_API_KEY} \ | ||
-X POST \ | ||
"${ATLAS_BASE_URL}/groups/${DRIVERS_ATLAS_GROUP_ID}/clusters/${FUNCTION_NAME}/restartPrimaries" | ||
} | ||
|
||
# Deploys a lambda function to the set stack name. | ||
deploy_lambda_function () | ||
{ | ||
echo "Deploying Lambda function..." | ||
sam deploy \ | ||
--stack-name "${FUNCTION_NAME}" \ | ||
--capabilities CAPABILITY_IAM \ | ||
--resolve-s3 \ | ||
--parameter-overrides "MongoDbUri=${MONGODB_URI}" \ | ||
--region ${AWS_REGION} | ||
} | ||
|
||
# Get the ARN for the Lambda function we created and export it. | ||
get_lambda_function_arn () | ||
{ | ||
echo "Getting Lambda function ARN..." | ||
LAMBDA_FUNCTION_ARN=$(sam list stack-outputs \ | ||
--stack-name ${FUNCTION_NAME} \ | ||
--region ${AWS_REGION} \ | ||
--output json | jq '.[] | select(.OutputKey == "MongoDBFunction") | .OutputValue' | tr -d '"' | ||
) | ||
echo "Lambda function ARN: $LAMBDA_FUNCTION_ARN" | ||
export LAMBDA_FUNCTION_ARN=$LAMBDA_FUNCTION_ARN | ||
} | ||
|
||
delete_lambda_function () | ||
{ | ||
echo "Deleting Lambda Function..." | ||
sam delete --stack-name ${FUNCTION_NAME} --no-prompts --region us-east-1 | ||
} | ||
|
||
cleanup () | ||
{ | ||
delete_lambda_function | ||
} | ||
|
||
trap cleanup EXIT SIGHUP | ||
|
||
cd "${TEST_LAMBDA_DIRECTORY}" | ||
|
||
sam build --use-container | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
|
||
deploy_lambda_function | ||
|
||
get_lambda_function_arn | ||
|
||
|
||
check_lambda_output () { | ||
if grep -q FunctionError output.json | ||
then | ||
echo "Exiting due to FunctionError!" | ||
exit 1 | ||
fi | ||
cat output.json | jq -r '.LogResult' | base64 --decode | ||
} | ||
|
||
aws lambda invoke --function-name ${LAMBDA_FUNCTION_ARN} --log-type Tail lambda-invoke-standard.json > output.json | ||
cat lambda-invoke-standard.json | ||
check_lambda_output | ||
|
||
echo "Sleeping 1 minute to build up some streaming protocol heartbeats..." | ||
sleep 60 | ||
aws lambda invoke --function-name ${LAMBDA_FUNCTION_ARN} --log-type Tail lambda-invoke-frozen.json > output.json | ||
cat lambda-invoke-frozen.json | ||
check_lambda_output | ||
|
||
restart_cluster_primary | ||
|
||
echo "Sleeping 1 minute to build up some streaming protocol heartbeats..." | ||
sleep 60 | ||
aws lambda invoke --function-name ${LAMBDA_FUNCTION_ARN} --log-type Tail lambda-invoke-outage.json > output.json | ||
cat lambda-invoke-outage.json | ||
check_lambda_output |
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,16 @@ | ||
#!/bin/bash | ||
|
||
set -ex | ||
|
||
. `dirname "$0"`/../spec/shared/shlib/distro.sh | ||
. `dirname "$0"`/../spec/shared/shlib/set_env.sh | ||
. `dirname "$0"`/functions.sh | ||
|
||
set_env_vars | ||
set_env_python | ||
set_env_ruby | ||
|
||
export MONGODB_URI=${MONGODB_URI} | ||
export TEST_LAMBDA_DIRECTORY=`dirname "$0"`/../spec/faas/ruby-sam-app | ||
|
||
. `dirname "$0"`/run-deployed-lambda-aws-tests.sh |
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
Submodule drivers-evergreen-tools
updated
33 files
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ AllCops: | |
NewCops: enable | ||
Exclude: | ||
- 'spec/shared/**/*' | ||
- 'spec/faas/**/*' | ||
- 'vendor/**/*' | ||
|
||
Bundler: | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was adding the FaaS task here, as another task under the atlas task group, so we only set up a single cluster per evergreen run. I think the fewer atlas instances we start, the better. It may be that this task group and the matrix variant that runs it need a better, more general name now, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that is a great idea! Updated accordingly.