-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add AWS Lambda example #986
Conversation
JAVA-4474
import org.bson.Document; | ||
|
||
// Start AWS Lambda Example 1 | ||
public class TestAwsLambdaHandler implements RequestHandler<String, String> { |
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.
Feel free to suggest a different name for this class. It can be anything we want.
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.
Perhaps ExampleAWSLambdaHandler
public class TestAwsLambdaHandler implements RequestHandler<String, String> { | |
public class ExampleAWSLambdaHandler implements RequestHandler<String, String> { |
private final MongoClient client; | ||
|
||
public TestAwsLambdaHandler() { | ||
client = MongoClients.create(System.getenv("MONGODB_URI")); |
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.
Create the client in the constructor
I wonder if we should also have an example of fetching those AWS credentials since it would help fit in the existing page structure. Eventually, we'll pull in all the examples and put them in tabs here. |
The credentials are fetched internally to the driver via reading environment variables or accessing the EC2 endpoint (I think... I haven't actually tried it). There is no code to show in the application for that, except perhaps showing the template for the connection string indicating the authMechanism of MONGODB-AWS. |
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.
LGTM. Would it also make sense to provide an example using this handler from within a lambda function? We'll make sure to point out how to structure the connection string much like we do for Node in https://www.mongodb.com/docs/atlas/manage-connections-aws-lambda/
import org.bson.Document; | ||
|
||
// Start AWS Lambda Example 1 | ||
public class TestAwsLambdaHandler implements RequestHandler<String, String> { |
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.
Perhaps ExampleAWSLambdaHandler
public class TestAwsLambdaHandler implements RequestHandler<String, String> { | |
public class ExampleAWSLambdaHandler implements RequestHandler<String, String> { |
The Java "standard" is to use lowercase for acronyms, so I went with ExampleAwsLambdaHandler |
JAVA-4474
Note that there is only one example rather than a separate one for MONGODB-AWS authentication. My argument for it is that the AWS credentials should properly be obtained by the driver via either environment variables or, perhaps, EC2 or ECS endpoints, and can be used just by specifying a MONGODB_URI environment variable like:
mongodb+srv://<host>/?authMechanism=MONGODB-AWS