Skip to content

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 8 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .evergreen/atlas
90 changes: 90 additions & 0 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ task_groups:
script: |
${PREPARE_SHELL}
echo "Setting up Atlas cluster"
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
Expand All @@ -492,6 +494,8 @@ task_groups:
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
echo "MONGODB_URI=${MONGODB_URI}"
- command: expansions.update
params:
file: src/atlas-expansion.yml
Expand All @@ -513,6 +517,52 @@ task_groups:
tasks:
- test-full-atlas-task

- name: test_aws_lambda_task_group
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800 # 30 minutes
setup_group:
- func: fetch source
- func: create expansions
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}
echo "Setting up Atlas cluster"
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
MONGODB_VERSION="7.0" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
- command: expansions.update
params:
file: src/atlas-expansion.yml
teardown_group:
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
tasks:
- test-aws-lambda-deployed

- name: testgcpkms_task_group
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800 # 30 minutes
Expand Down Expand Up @@ -702,6 +752,38 @@ tasks:
export AZUREKMS_VMNAME=${AZUREKMS_VMNAME}
export AZUREKMS_PRIVATEKEYPATH="/tmp/testazurekms_private_key_file"
AZUREKMS_CMD="TEST_FLE_AZURE_AUTO=1 RVM_RUBY=ruby-3.1 FLE=helper TOPOLOGY=standalone MONGODB_VERSION=6.0 MONGO_RUBY_DRIVER_AZURE_TENANT_ID="${MONGO_RUBY_DRIVER_AZURE_TENANT_ID}" MONGO_RUBY_DRIVER_AZURE_CLIENT_ID="${MONGO_RUBY_DRIVER_AZURE_CLIENT_ID}" MONGO_RUBY_DRIVER_AZURE_CLIENT_SECRET="${MONGO_RUBY_DRIVER_AZURE_CLIENT_SECRET}" MONGO_RUBY_DRIVER_AZURE_IDENTITY_PLATFORM_ENDPOINT="${MONGO_RUBY_DRIVER_AZURE_IDENTITY_PLATFORM_ENDPOINT}" MONGO_RUBY_DRIVER_AZURE_KEY_VAULT_ENDPOINT="${testazurekms_keyvaultendpoint}" MONGO_RUBY_DRIVER_AZURE_KEY_NAME="${testazurekms_keyname}" ./.evergreen/run-tests-azure.sh" .evergreen/csfle/azurekms/run-command.sh
- name: "test-aws-lambda-deployed"
commands:
- command: ec2.assume_role
params:
role_arn: ${LAMBDA_AWS_ROLE_ARN}
duration_seconds: 3600
- command: shell.exec
type: test
params:
working_dir: "src"
shell: "bash"
script: |
${PREPARE_SHELL}
export MONGODB_URI=${MONGODB_URI}
.evergreen/run-tests-deployed-lambda.sh
env:
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/spec/faas/ruby-sam-app
AWS_REGION: us-east-1
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
DRIVERS_TOOLS: ${DRIVERS_TOOLS}
DRIVERS_ATLAS_PUBLIC_API_KEY: ${DRIVERS_ATLAS_PUBLIC_API_KEY}
DRIVERS_ATLAS_PRIVATE_API_KEY: ${DRIVERS_ATLAS_PRIVATE_API_KEY}
DRIVERS_ATLAS_LAMBDA_USER: ${DRIVERS_ATLAS_LAMBDA_USER}
DRIVERS_ATLAS_LAMBDA_PASSWORD: ${DRIVERS_ATLAS_LAMBDA_PASSWORD}
DRIVERS_ATLAS_GROUP_ID: ${DRIVERS_ATLAS_GROUP_ID}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN}
LAMBDA_STACK_NAME: "dbx-ruby-lambda"
RVM_RUBY: ruby-3.2
MONGODB_URI: ${MONGODB_URI}
axes:

- id: preload
Expand Down Expand Up @@ -1689,3 +1771,11 @@ buildvariants:
display_name: "Atlas serverless ${ruby} single mongos"
tasks:
- name: test-serverless

- matrix_name: "aws-lambda"
matrix_spec:
ruby: "ruby-3.2"
os: ubuntu2204
display_name: "AWS Lambda"
tasks:
- name: test_aws_lambda_task_group
82 changes: 82 additions & 0 deletions .evergreen/config/common.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ task_groups:
script: |
${PREPARE_SHELL}

echo "Setting up Atlas cluster"

DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
Expand All @@ -489,6 +491,8 @@ task_groups:
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh

echo "MONGODB_URI=${MONGODB_URI}"
- command: expansions.update
params:
file: src/atlas-expansion.yml
Expand All @@ -510,6 +514,52 @@ task_groups:
tasks:
- test-full-atlas-task
Copy link
Contributor

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.

Copy link
Author

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.


- name: test_aws_lambda_task_group
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800 # 30 minutes
setup_group:
- func: fetch source
- func: create expansions
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}

echo "Setting up Atlas cluster"

DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
MONGODB_VERSION="7.0" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
- command: expansions.update
params:
file: src/atlas-expansion.yml
teardown_group:
- command: shell.exec
params:
shell: "bash"
working_dir: "src"
script: |
${PREPARE_SHELL}

DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
task_id="${task_id}" \
execution="${execution}" \
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
tasks:
- test-aws-lambda-deployed

- name: testgcpkms_task_group
setup_group_can_fail_task: true
setup_group_timeout_secs: 1800 # 30 minutes
Expand Down Expand Up @@ -699,3 +749,35 @@ tasks:
export AZUREKMS_VMNAME=${AZUREKMS_VMNAME}
export AZUREKMS_PRIVATEKEYPATH="/tmp/testazurekms_private_key_file"
AZUREKMS_CMD="TEST_FLE_AZURE_AUTO=1 RVM_RUBY=ruby-3.1 FLE=helper TOPOLOGY=standalone MONGODB_VERSION=6.0 MONGO_RUBY_DRIVER_AZURE_TENANT_ID="${MONGO_RUBY_DRIVER_AZURE_TENANT_ID}" MONGO_RUBY_DRIVER_AZURE_CLIENT_ID="${MONGO_RUBY_DRIVER_AZURE_CLIENT_ID}" MONGO_RUBY_DRIVER_AZURE_CLIENT_SECRET="${MONGO_RUBY_DRIVER_AZURE_CLIENT_SECRET}" MONGO_RUBY_DRIVER_AZURE_IDENTITY_PLATFORM_ENDPOINT="${MONGO_RUBY_DRIVER_AZURE_IDENTITY_PLATFORM_ENDPOINT}" MONGO_RUBY_DRIVER_AZURE_KEY_VAULT_ENDPOINT="${testazurekms_keyvaultendpoint}" MONGO_RUBY_DRIVER_AZURE_KEY_NAME="${testazurekms_keyname}" ./.evergreen/run-tests-azure.sh" .evergreen/csfle/azurekms/run-command.sh

- name: "test-aws-lambda-deployed"
commands:
- command: ec2.assume_role
params:
role_arn: ${LAMBDA_AWS_ROLE_ARN}
duration_seconds: 3600
- command: shell.exec
type: test
params:
working_dir: "src"
shell: "bash"
script: |
${PREPARE_SHELL}
export MONGODB_URI=${MONGODB_URI}
.evergreen/run-tests-deployed-lambda.sh
env:
TEST_LAMBDA_DIRECTORY: ${PROJECT_DIRECTORY}/spec/faas/ruby-sam-app
AWS_REGION: us-east-1
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
DRIVERS_TOOLS: ${DRIVERS_TOOLS}
DRIVERS_ATLAS_PUBLIC_API_KEY: ${DRIVERS_ATLAS_PUBLIC_API_KEY}
DRIVERS_ATLAS_PRIVATE_API_KEY: ${DRIVERS_ATLAS_PRIVATE_API_KEY}
DRIVERS_ATLAS_LAMBDA_USER: ${DRIVERS_ATLAS_LAMBDA_USER}
DRIVERS_ATLAS_LAMBDA_PASSWORD: ${DRIVERS_ATLAS_LAMBDA_PASSWORD}
DRIVERS_ATLAS_GROUP_ID: ${DRIVERS_ATLAS_GROUP_ID}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN}
LAMBDA_STACK_NAME: "dbx-ruby-lambda"
RVM_RUBY: ruby-3.2
MONGODB_URI: ${MONGODB_URI}
8 changes: 8 additions & 0 deletions .evergreen/config/standard.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,11 @@ buildvariants:
display_name: "Atlas serverless ${ruby} single mongos"
tasks:
- name: test-serverless

- matrix_name: "aws-lambda"
matrix_spec:
ruby: <%= latest_ruby %>
os: ubuntu2204
display_name: "AWS Lambda"
tasks:
- name: test_aws_lambda_task_group
117 changes: 117 additions & 0 deletions .evergreen/run-deployed-lambda-aws-tests.sh
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
16 changes: 16 additions & 0 deletions .evergreen/run-tests-deployed-lambda.sh
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ profile/benchmarking/data
secrets-export.sh
secrets-expansion.yml
atlas-expansion.yml
# AWS SAM-generated files
spec/faas/ruby-sam-app/.aws-sam
spec/faas/ruby-sam-app/events/event.json
2 changes: 1 addition & 1 deletion .mod/drivers-evergreen-tools
Submodule drivers-evergreen-tools updated 33 files
+0 −0 .evergreen/atlas/setup-variables.sh
+0 −0 .evergreen/auth_aws/prepare_aws_env.sh
+19 −3 .evergreen/auth_aws/setup_secrets.py
+4 −2 .evergreen/auth_aws/setup_secrets.sh
+4 −18 .evergreen/auth_oidc/Dockerfile
+2 −18 .evergreen/auth_oidc/docker_entry.sh
+20 −0 .evergreen/auth_oidc/docker_entry_base.sh
+2 −1 .evergreen/auth_oidc/oidc_write_orchestration.py
+24 −9 .evergreen/auth_oidc/start_local_server.sh
+120 −114 .evergreen/config.yml
+33 −21 .evergreen/csfle/azurekms/create-and-setup-vm.sh
+12 −0 .evergreen/csfle/azurekms/delete-vm.sh
+43 −0 .evergreen/docker/README.md
+47 −0 .evergreen/docker/run-local.sh
+33 −0 .evergreen/docker/ubuntu20.04/Dockerfile
+14 −0 .evergreen/docker/ubuntu20.04/base-entrypoint.sh
+5 −0 .evergreen/docker/ubuntu20.04/local-entrypoint.sh
+7 −0 .evergreen/docker/ubuntu20.04/test-entrypoint.sh
+24 −9 .evergreen/download-mongodb.sh
+5 −0 .evergreen/find-python3.sh
+11 −0 .evergreen/github_app/README.md
+89 −0 .evergreen/github_app/create_or_modify_comment.mjs
+20 −0 .evergreen/github_app/create_or_modify_comment.sh
+0 −0 .evergreen/github_app/index.js
+647 −0 .evergreen/github_app/package-lock.json
+25 −0 .evergreen/github_app/package.json
+22 −0 .evergreen/init-node-and-npm-env.sh
+112 −0 .evergreen/install-node.sh
+1 −1 .evergreen/make-docs.sh
+22 −5 .evergreen/run-orchestration.sh
+8 −3 .evergreen/start-orchestration.sh
+3 −0 .gitignore
+1 −1 action.yml
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ AllCops:
NewCops: enable
Exclude:
- 'spec/shared/**/*'
- 'spec/faas/**/*'
- 'vendor/**/*'

Bundler:
Expand Down
Loading