MongoDbPostInstallSetup

class aws_rfdk.MongoDbPostInstallSetup(scope, id, *, mongo_db, users, vpc, vpc_subnets=None)

Bases: constructs.Construct

This construct performs post-installation setup on a MongoDB database by logging into the database, and executing commands against it.

To provide this functionality, this construct will create an AWS Lambda function that is granted the ability to connect to the given MongoDB using its administrator credentials. This lambda is run automatically when you deploy or update the stack containing this construct. Logs for all AWS Lambdas are automatically recorded in Amazon CloudWatch.

Presently, the only post-installation action that this construct can perform is creating users. There are two types of users that it can create:

  1. Password-authenticated users – these users will be created within the ‘admin’ database.

  2. X.509-authenticated users – these users will be created within the ‘$external’ database.

Resources Deployed

  • An AWS Lambda that is used to connect to the MongoDB application, and perform post-installation tasks.

  • A CloudFormation Custom Resource that triggers execution of the Lambda on stack deployment, update, and deletion.

  • An Amazon CloudWatch log group that records history of the AWS Lambda’s execution.

Security Considerations

  • The AWS Lambda that is deployed through this construct will be created from a deployment package that is uploaded to your CDK bootstrap bucket during deployment. You must limit write access to your CDK bootstrap bucket to prevent an attacker from modifying the actions performed by this Lambda. We strongly recommend that you either enable Amazon S3 server access logging on your CDK bootstrap bucket, or enable AWS CloudTrail on your account to assist in post-incident analysis of compromised production environments.

  • The AWS Lambda function that is created by this resource has access to both the MongoDB administrator credentials, and the MongoDB application port. An attacker that can find a way to modify and execute this lambda could use it to modify or read any data in the database. You should not grant any additional actors/principals the ability to modify or execute this Lambda.

Parameters
  • scope (Construct) –

  • id (str) –

  • mongo_db (IMongoDb) – The MongoDB that we will connect to to perform the post-installation steps upon.

  • users (Union[MongoDbUsers, Dict[str, Any]]) – The Users that should be created in the MongoDB database. This construct will create these users only if they do not already exist. If a user does already exist, then it will not be modified.

  • vpc (IVpc) – The VPC in which to create the network endpoint for the lambda function that is created by this construct.

  • vpc_subnets (Union[SubnetSelection, Dict[str, Any], None]) – Where within the VPC to place the lambda function’s endpoint. Default: The instance is placed within a Private subnet.

Methods

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

node

The tree node.

Return type

Node

Static Methods

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

x (Any) – Any object.

Return type

bool

Returns

true if x is an object created from a class which extends Construct.