Skip to content

Commit c13ee3d

Browse files
authored
Merge pull request #13 from aws-samples/bugfix/non-available-region
fix: Only Supported Availability Zone is used
2 parents 3c21102 + e4e1486 commit c13ee3d

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

server/bin/ecs-saas-ref-template.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,3 @@ tenantTemplateStack.addDependency(sharedInfraStack);
144144
cdk.Tags.of(tenantTemplateStack).add('TenantId', tenantId);
145145
cdk.Tags.of(tenantTemplateStack).add('IsPooledDeploy', String(isPooledDeploy));
146146
cdk.Aspects.of(tenantTemplateStack).add(new DestroyPolicySetter());
147-
148-
const ecsSaaSPipeline = new TenantUpdatePipeline(app, 'tenant-update-stack', {
149-
tenantMappingTable: coreAppPlaneStack.tenantMappingTable,
150-
codeCommitRepositoryName: codeCommitRepositoryName,
151-
env: {
152-
account: process.env.CDK_DEFAULT_ACCOUNT,
153-
region: process.env.CDK_DEFAULT_REGION
154-
}
155-
});
156-
cdk.Aspects.of(ecsSaaSPipeline).add(new DestroyPolicySetter());

server/lib/shared-infra/shared-infra-stack.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path';
33
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
44
import * as targets from 'aws-cdk-lib/aws-elasticloadbalancingv2-targets';
55
import { type Construct } from 'constructs';
6-
import { Stack, type StackProps, type Environment, Tags, CfnOutput } from 'aws-cdk-lib';
6+
import { Stack, type StackProps, type Environment, Tags, Fn, CfnOutput } from 'aws-cdk-lib';
77
import { StringParameter } from 'aws-cdk-lib/aws-ssm';
88
import { ApiGateway } from './api-gateway';
99
import { type ApiKeySSMParameterNames } from '../interfaces/api-key-ssm-parameter-names';
@@ -34,10 +34,15 @@ export class SharedInfraStack extends Stack {
3434
constructor (scope: Construct, id: string, props: SharedInfraProps) {
3535
super(scope, id);
3636

37+
const azs = Fn.getAzs(this.region);
3738
this.vpc = new ec2.Vpc(this, 'sbt-ecs-vpc', {
3839
// maxAzs: 3,
3940
ipAddresses: ec2.IpAddresses.cidr('10.0.0.0/16'),
40-
availabilityZones: [`${props.env.region}a`, `${props.env.region}b`, `${props.env.region}c`],
41+
availabilityZones: [
42+
Fn.select(0, azs),
43+
Fn.select(1, azs),
44+
Fn.select(2, azs),
45+
],
4146
flowLogs: {
4247
'sbt-ecs-vpcFlowLog': {
4348
destination: ec2.FlowLogDestination.toCloudWatchLogs(),
@@ -168,6 +173,20 @@ export class SharedInfraStack extends Stack {
168173
exportName: 'EcsVpcId'
169174
});
170175

176+
177+
new CfnOutput(this, 'az1', {
178+
value: this.vpc.availabilityZones[0],
179+
exportName: 'az1'
180+
});
181+
new CfnOutput(this, 'az2', {
182+
value: this.vpc.availabilityZones[1],
183+
exportName: 'az2'
184+
});
185+
new CfnOutput(this, 'az3', {
186+
value: this.vpc.availabilityZones[2],
187+
exportName: 'az3'
188+
});
189+
171190
new CfnOutput(this, 'PrivSubId1EcsSbt', {
172191
value: this.vpc.privateSubnets[0].subnetId,
173192
exportName: 'PrivSubId1EcsSbt'

server/lib/tenant-template/ecs-cluster.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ export class EcsCluster extends cdk.NestedStack {
4545
this.isEc2Tier = props.isEc2Tier;
4646

4747
this.vpc = ec2.Vpc.fromVpcAttributes(this, 'Vpc', {
48-
availabilityZones: [`${props.env.region}a`, `${props.env.region}b`, `${props.env.region}c`],
48+
availabilityZones: [
49+
cdk.Fn.importValue('az1'),
50+
cdk.Fn.importValue('az2'),
51+
cdk.Fn.importValue('az3')
52+
],
4953
privateSubnetIds: [
5054
cdk.Fn.importValue('PrivSubId1EcsSbt'),
5155
cdk.Fn.importValue('PrivSubId2EcsSbt'),
@@ -101,8 +105,7 @@ export class EcsCluster extends cdk.NestedStack {
101105
clusterName = `${props.stageName}-advanced-${cdk.Stack.of(this).account}`
102106
}
103107

104-
if('advanced' !== props.tier.toLocaleLowerCase() || 'ACTIVE' !== props.advancedCluster ) {
105-
// console.error('No Cluster Found -->', this.cluster);
108+
if('advanced' !== props.tier.toLocaleLowerCase() || 'ACTIVE' !== props.advancedCluster ) {
106109
this.cluster = new ecs.Cluster(this, 'EcsCluster', {
107110
clusterName,
108111
vpc: this.vpc,

0 commit comments

Comments
 (0)