Skip to content

Commit e075ae6

Browse files
committed
add supporting files
1 parent 20b52dd commit e075ae6

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// This example creates a project and a flex cluster in Atlas using the L1 resources.
2+
import * as cdk from 'aws-cdk-lib';
3+
import { Construct } from 'constructs';
4+
import { CfnProject, CfnFlexCluster } from 'awscdk-resources-mongodbatlas';
5+
6+
interface AtlasStackProps {
7+
readonly orgId: string;
8+
readonly profile: string;
9+
readonly projName: string;
10+
readonly clusterName: string;
11+
readonly region: string;
12+
readonly backingProvider: string;
13+
}
14+
15+
export class CdkFlexClusterStack extends cdk.Stack {
16+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
17+
super(scope, id, props);
18+
19+
const atlasProps = this.getContextProps();
20+
21+
const projectRes = new CfnProject(this, 'ProjectResource', {
22+
name: atlasProps.projName,
23+
orgId: atlasProps.orgId,
24+
profile: atlasProps.profile
25+
});
26+
27+
const flexClusterRes = new CfnFlexCluster(this, 'FlexClusterResource', {
28+
name: atlasProps.clusterName,
29+
projectId: projectRes.attrId,
30+
profile: atlasProps.profile,
31+
providerSettings: {
32+
backingProviderName: atlasProps.backingProvider,
33+
regionName: atlasProps.region,
34+
},
35+
tags: [
36+
{
37+
key: "env",
38+
value: "development",
39+
},
40+
],
41+
});
42+
43+
// Output the connection strings
44+
new cdk.CfnOutput(this, 'FlexClusterId', {
45+
value: flexClusterRes.attrId,
46+
description: 'Flex Cluster ID',
47+
});
48+
49+
new cdk.CfnOutput(this, 'FlexClusterState', {
50+
value: flexClusterRes.attrStateName,
51+
description: 'Flex Cluster State',
52+
});
53+
54+
new cdk.CfnOutput(this, 'FlexClusterMongoDBVersion', {
55+
value: flexClusterRes.attrMongoDBVersion,
56+
description: 'MongoDB Version',
57+
});
58+
}
59+
60+
getContextProps(): AtlasStackProps {
61+
const orgId = this.node.tryGetContext('orgId');
62+
if (!orgId) {
63+
throw "No context value specified for orgId. Please specify via the cdk context."
64+
}
65+
const projName = this.node.tryGetContext('projName') ?? 'test-flex-proj';
66+
const profile = this.node.tryGetContext('profile') ?? 'default';
67+
const clusterName = this.node.tryGetContext('clusterName') ?? 'test-flex-cluster';
68+
const region = this.node.tryGetContext('region') ?? "US_EAST_1";
69+
const backingProvider = this.node.tryGetContext('backingProvider') ?? "AWS";
70+
71+
return {
72+
projName,
73+
orgId,
74+
profile,
75+
clusterName,
76+
region,
77+
backingProvider,
78+
}
79+
}
80+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# flex-cluster
2+
3+
The official [MongoDB Atlas](https://www.mongodb.com/) AWS CDK resource for Node.js.
4+
5+
> AWS CDK [L1 construct] and data structures for the [AWS CloudFormation Registry] type `MongoDB::Atlas::FlexCluster`.
6+
7+
[L1 construct]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html
8+
[AWS CloudFormation Registry]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html
9+
10+
## Description
11+
12+
The flex cluster resource provides access to your flex cluster configurations. The resource lets you create, edit and delete flex clusters. The resource requires your Project ID.
13+
14+
MongoDB Atlas Flex clusters provide a flexible, scalable, and cost-optimized solution for low-traffic applications and variable workloads. Flex clusters automatically scale compute and storage resources based on demand, offering a pay-as-you-go model.
15+
16+
## MongoDB Atlas API Docs
17+
18+
For more information about the API refer to: [API Endpoints](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Flex-Clusters)
19+
20+
## Usage
21+
22+
In order to use this library, you will need to activate this AWS CloudFormation Registry type in your account. You can do this via the AWS Management Console or using the [AWS CLI](https://aws.amazon.com/cli/) using the following command:
23+
24+
```sh
25+
aws cloudformation activate-type \
26+
--type-name MongoDB::Atlas::FlexCluster \
27+
--publisher-id <PUBLISHER_ID> \
28+
--type RESOURCE \
29+
--execution-role-arn ROLE-ARN
30+
```
31+
32+
Alternatively:
33+
34+
```sh
35+
aws cloudformation activate-type \
36+
--public-type-arn arn:aws:cloudformation:us-east-1::type/resource/<PUBLISHER_ID>/MongoDB-Atlas-FlexCluster \
37+
--execution-role-arn ROLE-ARN
38+
```
39+
40+
You can find more information about activating this type in the [AWS CloudFormation documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry-public.html).
41+
42+
## Example: [flex-cluster.ts](../../../examples/l1-resources/flex-cluster.ts)
43+
44+
```ts
45+
import { CfnFlexCluster } from 'awscdk-resources-mongodbatlas';
46+
47+
const flexClusterRes = new CfnFlexCluster(this, 'FlexClusterResource', {
48+
name: atlasProps.clusterName,
49+
projectId: projectRes.attrId,
50+
profile: atlasProps.profile,
51+
providerSettings: {
52+
backingProviderName: atlasProps.backingProvider,
53+
regionName: atlasProps.region,
54+
},
55+
tags: [
56+
{
57+
key: "env",
58+
value: "development",
59+
},
60+
],
61+
});
62+
```
63+
64+
## Feedback
65+
66+
This library is auto-generated and published to all supported programming languages by the [cdklabs/cdk-cloudformation] project based on the API schema published for `MongoDB::Atlas::FlexCluster`.
67+
68+
* Issues related to this generated library should be [reported here](https://github.com/cdklabs/cdk-cloudformation/issues/new?title=Issue+with+%40cdk-cloudformation%2Fmongodb-atlas-flexcluster+v1.0.0).
69+
* Issues related to `MongoDB::Atlas::FlexCluster` should be reported to the [publisher](https://github.com/mongodb/mongodbatlas-cloudformation-resources/issues).
70+
* Feature requests should be [reported here](https://feedback.mongodb.com/forums/924145-atlas?category_id=392596)
71+
72+
[cdklabs/cdk-cloudformation]: https://github.com/cdklabs/cdk-cloudformation
73+
74+
## License
75+
76+
Distributed under the Apache-2.0 License.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as cdk from "aws-cdk-lib";
2+
import { CfnFlexCluster } from "./index";
3+
4+
const app = new cdk.App();
5+
const stack = new cdk.Stack(app, "atlas-flex-cluster-test", {
6+
env: {
7+
region: process.env.CDK_DEFAULT_REGION,
8+
account: process.env.CDK_DEFAULT_ACCOUNT,
9+
},
10+
});
11+
12+
const atlasProject = "";
13+
14+
new CfnFlexCluster(stack, "AtlasFlexCluster", {
15+
projectId: atlasProject,
16+
name: "TestFlexCluster",
17+
providerSettings: {
18+
backingProviderName: "AWS",
19+
regionName: "US_EAST_1",
20+
},
21+
tags: [
22+
{
23+
key: "env",
24+
value: "development",
25+
},
26+
],
27+
});

0 commit comments

Comments
 (0)