Skip to content

Commit

Permalink
feat: number of NAT gateways is customizable (#426)
Browse files Browse the repository at this point in the history
* NAT Gatewayの数をcdk.jsonでカスタマイズできるようにする

* テストケース修正

* インデント修正

* readme修正

* type修正。NATゲートウェイをNAT Gatewayに表記を統一
  • Loading branch information
fsatsuki committed Jul 3, 2024
1 parent ad03f92 commit af34def
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ By default, this sample does not restrict the domains for sign-up email addresse
"allowedSignUpEmailDomains": ["example.com"],
```

### Customize Number of NAT Gateway

By default, this sample deploys 2 NAT gateways, but you can change the number of NAT gateways if you don't need 2 NAT gateways to reduce costs. Open `cdk.json` and change this parameter 'number of NAT gateways'.

```ts
"natgatewayCount": 2
```

### External Identity Provider

This sample supports external identity provider. Currently we support [Google](./docs/idp/SET_UP_GOOGLE.md) and [custom OIDC provider](./docs/idp/SET_UP_CUSTOM_OIDC.md).
Expand Down
4 changes: 4 additions & 0 deletions cdk/bin/bedrock-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const SELF_SIGN_UP_ENABLED: boolean = app.node.tryGetContext("selfSignUpEnabled"
const EMBEDDING_CONTAINER_VCPU:number = app.node.tryGetContext("embeddingContainerVcpu")
const EMBEDDING_CONTAINER_MEMORY:number = app.node.tryGetContext("embeddingContainerMemory")

// how many nat gateways
const NATGATEWAY_COUNT:number = app.node.tryGetContext("natgatewayCount")

// WAF for frontend
// 2023/9: Currently, the WAF for CloudFront needs to be created in the North America region (us-east-1), so the stacks are separated
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-webacl.html
Expand Down Expand Up @@ -76,5 +79,6 @@ const chat = new BedrockChatStack(app, `BedrockChatStack`, {
embeddingContainerVcpu: EMBEDDING_CONTAINER_VCPU,
embeddingContainerMemory: EMBEDDING_CONTAINER_MEMORY,
selfSignUpEnabled: SELF_SIGN_UP_ENABLED,
natgatewayCount: NATGATEWAY_COUNT,
});
chat.addDependency(waf);
3 changes: 2 additions & 1 deletion cdk/cdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"start": {}
},
"embeddingContainerVcpu": 2048,
"embeddingContainerMemory": 4096
"embeddingContainerMemory": 4096,
"natgatewayCount": 2
}
}
5 changes: 4 additions & 1 deletion cdk/lib/bedrock-chat-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface BedrockChatStackProps extends StackProps {
readonly embeddingContainerVcpu: number;
readonly embeddingContainerMemory: number;
readonly selfSignUpEnabled: boolean;
readonly natgatewayCount: number;
}

export class BedrockChatStack extends cdk.Stack {
Expand All @@ -47,7 +48,9 @@ export class BedrockChatStack extends cdk.Stack {
});
const cronSchedule = createCronSchedule(props.rdsSchedules);

const vpc = new ec2.Vpc(this, "VPC", {});
const vpc = new ec2.Vpc(this, "VPC", {
natGateways: props.natgatewayCount
});
vpc.publicSubnets.forEach((subnet) => {
(subnet.node.defaultChild as ec2.CfnSubnet).mapPublicIpOnLaunch = false;
});
Expand Down
9 changes: 7 additions & 2 deletions cdk/test/cdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ describe("Fine-grained Assertions Test", () => {
start: {},
},
enableMistral: false,
selfSignUpEnabled: true,
selfSignUpEnabled: true,
embeddingContainerVcpu: 1024,
embeddingContainerMemory: 2048,
natgatewayCount: 2
}
);
const hasGoogleProviderTemplate = Template.fromStack(
Expand Down Expand Up @@ -89,9 +90,10 @@ describe("Fine-grained Assertions Test", () => {
start: {},
},
enableMistral: false,
selfSignUpEnabled: true,
selfSignUpEnabled: true,
embeddingContainerVcpu: 1024,
embeddingContainerMemory: 2048,
natgatewayCount: 2
}
);
const hasOidcProviderTemplate = Template.fromStack(hasOidcProviderStack);
Expand Down Expand Up @@ -140,6 +142,7 @@ describe("Fine-grained Assertions Test", () => {
selfSignUpEnabled: true,
embeddingContainerVcpu: 1024,
embeddingContainerMemory: 2048,
natgatewayCount: 2
});
const template = Template.fromStack(stack);

Expand Down Expand Up @@ -187,6 +190,7 @@ describe("Scheduler Test", () => {
selfSignUpEnabled: true,
embeddingContainerVcpu: 1024,
embeddingContainerMemory: 2048,
natgatewayCount: 2
});
const template = Template.fromStack(hasScheduleStack);
template.hasResourceProperties("AWS::Scheduler::Schedule", {
Expand Down Expand Up @@ -217,6 +221,7 @@ describe("Scheduler Test", () => {
selfSignUpEnabled: true,
embeddingContainerVcpu: 1024,
embeddingContainerMemory: 2048,
natgatewayCount: 2
});
const template = Template.fromStack(defaultStack);
// The stack should have only 1 rule for exporting the data from ddb to s3
Expand Down
8 changes: 8 additions & 0 deletions docs/README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ GENERATION_CONFIG = {
"allowedSignUpEmailDomains": ["example.com"],
```

### NAT Gateway数のカスタマイズ

このサンプルはデフォルトでは2つの NAT Gatewayがデプロイされますが、2つの NAT Gatewayが不要な場合は、NAT Gatewayの数を変更してコストを削減できます。`cdk.json`を開き、 `natgatewayCount` のパラメータを変更してください。

```ts
"natgatewayCount": 2
```

### リソースの削除

cli および CDK を利用されている場合、`cdk destroy`を実行してください。そうでない場合は[CloudFormation](https://console.aws.amazon.com/cloudformation/home)へアクセスし、手動で`BedrockChatStack`および`FrontendWafStack`を削除してください。なお`FrontendWafStack``us-east-1` リージョンにあります。
Expand Down

0 comments on commit af34def

Please sign in to comment.