Skip to content

Commit 7199675

Browse files
authored
Merge pull request #20 from aws-samples/SBTv0.4.3
feature: SBT v0.5.0 applied
2 parents 6ada7a3 + b74e678 commit 7199675

File tree

13 files changed

+204
-104
lines changed

13 files changed

+204
-104
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ If you are using Cloud9, make sure to use `Amazon Linux 2023` AMI for the EC2 wi
3434
- Make sure you have [AWS CLI 2.14](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) or above installed.
3535
- Make sure you have [Docker Engine](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-docker.html) installed.
3636
- Make sure you have the latest version of [AWS CDK CLI](https://docs.aws.amazon.com/cdk/latest/guide/cli.html) installed. Not having the release version of CDK can cause deployment issues.
37-
- Make sure you have the latest version of [git-remote-codecommit](https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-git-remote-codecommit.html) installed.
3837
- Make sure that you have Node 18 or above.
3938
- Make sure that you have Git installed.
4039

@@ -55,7 +54,7 @@ Note that, ```build-application.sh``` builds docker images of sample SaaS applic
5554

5655
And, ```install.sh``` deploys the following:
5756

58-
- Creates an AWS CodeCommit repo in your AWS account and pushes this reference solution code to the repo
57+
- Creates an AWS S3 bucket in your AWS account and pushes this reference solution code to the bucket
5958
- Cdk stack `controlplane-stack` which provisions
6059
- SaaS Builder Toolkit(SBT) control plane components which allows infrastructure to provision/de-provision a tenant.
6160
- Cdk stack `coreappplane-stack` which provisions
@@ -64,8 +63,6 @@ And, ```install.sh``` deploys the following:
6463
- Shared application infrastructure like Amazon VPC, Amazon API Gateway, and Load balancers.
6564
- Cdk stack `tenant-template-stack`, which provisions
6665
- ECS Cluster and ECS services order, product & user microservices.
67-
- Cdk stack `tenant-update-stack` which provisions
68-
- AWS Code Pipeline to update tenant deployments on any changes to source in CodeCommit repo.
6966

7067
## Steps to Clean-up
7168

scripts/cleanup.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ if ! confirm; then
2121
fi
2222

2323
export REGION=$(aws ec2 describe-availability-zones --output text --query 'AvailabilityZones[0].[RegionName]')
24+
export ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
2425

2526
echo "$(date) emptying out buckets..."
2627
for i in $(aws s3 ls | awk '{print $3}' | grep -E "^tenant-update-stack-*|^controlplane-stack-*|^core-appplane-*|^saas-reference-architecture-*"); do
@@ -38,7 +39,7 @@ cd ../server
3839
npm install
3940

4041
export CDK_PARAM_SYSTEM_ADMIN_EMAIL="NA"
41-
export CDK_PARAM_S3_BUCKET_NAME="saas-reference-architecture-ecs-$REGION"
42+
export CDK_PARAM_S3_BUCKET_NAME="saas-reference-architecture-ecs-$ACCOUNT_ID-$REGION"
4243
export CDK_PARAM_COMMIT_ID="NA"
4344
export CDK_PARAM_REG_API_GATEWAY_URL="NA"
4445
export CDK_PARAM_EVENT_BUS_ARN=arn:aws:service:::resource
@@ -60,7 +61,7 @@ versions=$(aws s3api list-object-versions --bucket $CDK_PARAM_S3_BUCKET_NAME --o
6061
if [ "$versions" -gt 0 ]; then
6162
aws s3api list-object-versions --bucket $CDK_PARAM_S3_BUCKET_NAME --output json \
6263
| jq '{"Objects": [.Versions[] | {Key: .Key, VersionId: .VersionId}]}' > $TEMP_FILE
63-
aws s3api delete-objects --bucket $CDK_PARAM_S3_BUCKET_NAME --delete file://$TEMP_FILE
64+
aws s3api delete-objects --bucket $CDK_PARAM_S3_BUCKET_NAME --delete file://$TEMP_FILE --no-cli-pager
6465
fi
6566

6667
# Deleting object markers
@@ -71,7 +72,7 @@ delete_markers=$(aws s3api list-object-versions --bucket $CDK_PARAM_S3_BUCKET_NA
7172
if [ "$delete_markers" -gt 0 ]; then
7273
aws s3api list-object-versions --bucket $CDK_PARAM_S3_BUCKET_NAME --output json \
7374
| jq '{"Objects": [.DeleteMarkers[] | {Key: .Key, VersionId: .VersionId}]}' > $TEMP_FILE
74-
aws s3api delete-objects --bucket $CDK_PARAM_S3_BUCKET_NAME --delete file://$TEMP_FILE
75+
aws s3api delete-objects --bucket $CDK_PARAM_S3_BUCKET_NAME --delete file://$TEMP_FILE --no-cli-pager
7576
fi
7677

7778

scripts/deprovision-tenant.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ if [[ $TIER == "PREMIUM" || $TIER == "ADVANCED" ]]; then
8686
STACK_NAME=$(sed -e 's/^"//' -e 's/"$//' <<<$STACK_NAME)
8787
echo "Stack name from $TENANT_STACK_MAPPING_TABLE is $STACK_NAME"
8888
# Copy to S3 Bucket
89-
export CDK_PARAM_S3_BUCKET_NAME="saas-reference-architecture-ecs-$REGION"
89+
export CDK_PARAM_S3_BUCKET_NAME="saas-reference-architecture-ecs-$ACCOUNT_ID-$REGION"
9090
export CDK_SOURCE_NAME="source.zip"
9191
CDK_PARAM_COMMIT_ID=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query "Stacks[0].Outputs[?OutputKey=='S3SourceVersion'].OutputValue" --output text)
9292

scripts/install.sh

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ if [[ -z "$CDK_PARAM_SYSTEM_ADMIN_EMAIL" ]]; then
88
fi
99

1010
REGION=$(aws ec2 describe-availability-zones --output text --query 'AvailabilityZones[0].[RegionName]') # Region setting
11-
export CDK_PARAM_S3_BUCKET_NAME="saas-reference-architecture-ecs-$REGION"
11+
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
12+
13+
export CDK_PARAM_S3_BUCKET_NAME="saas-reference-architecture-ecs-$ACCOUNT_ID-$REGION"
1214

1315
# Create S3 Bucket for provision source.
1416

1517
if aws s3api head-bucket --bucket $CDK_PARAM_S3_BUCKET_NAME 2>/dev/null; then
1618
echo "Bucket $CDK_PARAM_S3_BUCKET_NAME already exists."
1719
else
18-
echo "Bucket $CDK_PARAM_S3_BUCKET_NAME does not exist. Creating a new bucket in $REGION region"
20+
echo "Bucket $CDK_PARAM_S3_BUCKET_NAME does not exist. Creating a new bucket in $REGION region in $ACCOUNT_ID"
1921

2022
if [ "$REGION" == "us-east-1" ]; then
2123
aws s3api create-bucket --bucket $CDK_PARAM_S3_BUCKET_NAME
@@ -43,10 +45,10 @@ else
4345
fi
4446
fi
4547

46-
echo "Bucket exists2: $CDK_PARAM_S3_BUCKET_NAME"
48+
echo "Bucket exists: $CDK_PARAM_S3_BUCKET_NAME"
4749

4850
cd ../
49-
zip -r source.zip . -x ".git/*" -x "**/node_modules/*" -x "**/cdk.out/*" -x "**/.aws-sam/*"
51+
zip -rq source.zip . -x ".git/*" -x "**/node_modules/*" -x "**/cdk.out/*" -x "**/.aws-sam/*"
5052
export CDK_PARAM_COMMIT_ID=$(aws s3api put-object --bucket "${CDK_PARAM_S3_BUCKET_NAME}" --key "source.zip" --body "./source.zip" --output text)
5153

5254
rm source.zip
@@ -61,18 +63,32 @@ cd ./server
6163
export ECR_REGION=$(aws ec2 describe-availability-zones --output text --query 'AvailabilityZones[0].[RegionName]')
6264
export ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
6365
sed "s/<REGION>/$ECR_REGION/g; s/<ACCOUNT_ID>/$ACCOUNT_ID/g" ./service-info.txt > ./lib/service-info.json
64-
65-
npm install
66-
6766
# npx cdk bootstrap
6867
export CDK_PARAM_ONBOARDING_DETAIL_TYPE='Onboarding'
6968
export CDK_PARAM_PROVISIONING_DETAIL_TYPE=$CDK_PARAM_ONBOARDING_DETAIL_TYPE
7069
export CDK_PARAM_OFFBOARDING_DETAIL_TYPE='Offboarding'
7170
export CDK_PARAM_DEPROVISIONING_DETAIL_TYPE=$CDK_PARAM_OFFBOARDING_DETAIL_TYPE
7271
export CDK_PARAM_TIER='basic'
72+
export CDK_PARAM_STAGE='prod'
73+
74+
export CDK_BASIC_CLUSTER="$CDK_PARAM_STAGE-$CDK_PARAM_TIER"
75+
SERVICES=$(aws ecs list-services --cluster $CDK_BASIC_CLUSTER --query 'serviceArns[*]' --output text)
76+
for SERVICE in $SERVICES; do
77+
SERVICE_NAME=$(echo $SERVICE | rev | cut -d '/' -f 1 | rev)
78+
79+
echo -n "==== Service Connect Disable: "
80+
aws ecs update-service \
81+
--cluster $CDK_BASIC_CLUSTER \
82+
--service $SERVICE_NAME \
83+
--service-connect-configuration 'enabled=false' \
84+
--no-cli-pager --query 'service.serviceArn' --output text
85+
86+
done
87+
88+
npm install
7389

7490
npx cdk bootstrap
75-
npx cdk deploy --all --require-approval never #--concurrency 10 --asset-parallelism true
91+
npx cdk deploy --all --require-approval=never
7692

7793
# Get SaaS application url
7894
ADMIN_SITE_URL=$(aws cloudformation describe-stacks --stack-name controlplane-stack --query "Stacks[0].Outputs[?OutputKey=='adminSiteUrl'].OutputValue" --output text)

scripts/provision-tenant.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export REGION=$(aws ec2 describe-availability-zones --output text --query 'Avail
1616
export ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
1717

1818
# Download from the ecs reference solution Bucket
19-
export CDK_PARAM_S3_BUCKET_NAME="saas-reference-architecture-ecs-$REGION"
19+
export CDK_PARAM_S3_BUCKET_NAME="saas-reference-architecture-ecs-$ACCOUNT_ID-$REGION"
2020
export CDK_SOURCE_NAME="source.zip"
2121

2222
VERSIONS=$(aws s3api list-object-versions --bucket "$CDK_PARAM_S3_BUCKET_NAME" --prefix "$CDK_SOURCE_NAME" --query 'Versions[?IsLatest==`true`].{VersionId:VersionId}' --output text 2>&1)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const defaultSystemAdminRoleName = 'SystemAdmin';
4848
// optional input parameters
4949
const systemAdminRoleName =
5050
process.env.CDK_PARAM_SYSTEM_ADMIN_ROLE_NAME || defaultSystemAdminRoleName;
51-
const stageName = process.env.CDK_PARAM_STAGE_NAME || defaultStageName;
51+
const stageName = process.env.CDK_PARAM_STAGE || defaultStageName;
5252
const lambdaReserveConcurrency = Number(
5353
process.env.CDK_PARAM_LAMBDA_RESERVE_CONCURRENCY || defaultLambdaReserveConcurrency
5454
);

server/lib/bootstrap-template/core-appplane-stack.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class CoreAppPlaneStack extends cdk.Stack {
4545
partitionKey: { name: 'tenantId', type: AttributeType.STRING }
4646
});
4747

48-
const provisioningJobRunnerProps = {
48+
const provisioningScriptJobProps = {
4949
permissions: PolicyDocument.fromJson(
5050
JSON.parse(`
5151
{
@@ -82,7 +82,7 @@ export class CoreAppPlaneStack extends cdk.Stack {
8282
eventManager: props.eventManager
8383
};
8484

85-
const deprovisioningJobRunnerProps = {
85+
const deprovisioningScriptJobProps = {
8686
permissions: PolicyDocument.fromJson(
8787
JSON.parse(`
8888
{
@@ -114,17 +114,17 @@ export class CoreAppPlaneStack extends cdk.Stack {
114114
eventManager: props.eventManager
115115
};
116116

117-
const provisioningJobRunner: sbt.BashJobRunner = new sbt.BashJobRunner(this,
118-
'provisioningJobRunner', provisioningJobRunnerProps
117+
const provisioningScriptJob: sbt.ProvisioningScriptJob = new sbt.ProvisioningScriptJob(this,
118+
'provisioningScriptJob', provisioningScriptJobProps
119119
);
120120

121-
const deprovisioningJobRunner: sbt.BashJobRunner = new sbt.BashJobRunner(this,
122-
'deprovisioningJobRunner', deprovisioningJobRunnerProps
121+
const deprovisioningScriptJob: sbt.ProvisioningScriptJob = new sbt.DeprovisioningScriptJob(this,
122+
'deprovisioningScriptJob', deprovisioningScriptJobProps
123123
);
124124

125125
new sbt.CoreApplicationPlane(this, 'coreappplane-sbt', {
126126
eventManager: props.eventManager,
127-
jobRunnersList: [provisioningJobRunner, deprovisioningJobRunner]
127+
scriptJobs: [provisioningScriptJob, deprovisioningScriptJob]
128128
});
129129

130130
const staticSite = new StaticSite(this, 'TenantWebUI', {

server/lib/bootstrap-template/static-site.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as s3deployment from 'aws-cdk-lib/aws-s3-deployment';
66
import * as iam from 'aws-cdk-lib/aws-iam';
77
import * as s3 from 'aws-cdk-lib/aws-s3';
88
import { Construct } from 'constructs';
9-
import { Fn, RemovalPolicy, StringConcat } from 'aws-cdk-lib';
9+
import { Fn, RemovalPolicy } from 'aws-cdk-lib';
1010
import { addTemplateTag } from '../utilities/helper-functions';
1111

1212

server/lib/cdknag/control-plane-nag.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class ControlPlaneNag extends Construct {
120120
[
121121
{
122122
id: 'AwsSolutions-IAM4',
123-
reason: 'CDKBucket substitute codecommit',
123+
reason: 'CDK S3 Bucket for Ref',
124124
appliesTo: [
125125
'Policy::arn:<AWS::Partition>:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
126126
]
@@ -134,7 +134,7 @@ export class ControlPlaneNag extends Construct {
134134
[
135135
{
136136
id: 'AwsSolutions-L1',
137-
reason: 'CDKBucket substitute codecommit',
137+
reason: 'CDK S3 Bucket for Ref',
138138
}
139139
]
140140
);
@@ -147,7 +147,7 @@ export class ControlPlaneNag extends Construct {
147147
[
148148
{
149149
id: 'AwsSolutions-S1',
150-
reason: 'CDKBucket substitute codecommit',
150+
reason: 'CDK S3 Bucket for Ref',
151151
}
152152
]
153153
);
@@ -159,7 +159,7 @@ export class ControlPlaneNag extends Construct {
159159
[
160160
{
161161
id: 'AwsSolutions-CB4',
162-
reason: 'CDKBucket substitute codecommit',
162+
reason: 'CDK S3 Bucket for Ref',
163163
}
164164
]
165165
);

server/lib/cdknag/core-app-plane-nag.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export class CoreAppPlaneNag extends Construct {
2727
NagSuppressions.addResourceSuppressionsByPath(
2828
cdk.Stack.of(this),
2929
[
30-
'core-appplane-stack/provisioningJobRunner/codeBuildProvisionProjectRole/Resource',
31-
'core-appplane-stack/deprovisioningJobRunner/codeBuildProvisionProjectRole/Resource',
30+
'core-appplane-stack/provisioningScriptJob/codeBuildProvisionProjectRole/Resource',
31+
'core-appplane-stack/deprovisioningScriptJob/codeBuildProvisionProjectRole/Resource',
3232
],
3333
[
3434
{
@@ -83,7 +83,7 @@ export class CoreAppPlaneNag extends Construct {
8383
[
8484
{
8585
id: 'AwsSolutions-IAM4',
86-
reason: 'CDKBucket substitute codecommit',
86+
reason: 'CDK S3 Bucket for Ref',
8787
appliesTo: [
8888
'Policy::arn:<AWS::Partition>:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
8989
]
@@ -99,7 +99,7 @@ export class CoreAppPlaneNag extends Construct {
9999
[
100100
{
101101
id: 'AwsSolutions-S1',
102-
reason: 'CDKBucket substitute codecommit',
102+
reason: 'CDK S3 Bucket for Ref',
103103
}
104104
]
105105
);
@@ -110,7 +110,7 @@ export class CoreAppPlaneNag extends Construct {
110110
[
111111
{
112112
id: 'AwsSolutions-CB4',
113-
reason: 'CDKBucket substitute codecommit',
113+
reason: 'CDK S3 Bucket for Ref',
114114
}
115115
]
116116
);
@@ -120,7 +120,7 @@ export class CoreAppPlaneNag extends Construct {
120120
[
121121
{
122122
id: 'AwsSolutions-L1',
123-
reason: 'CDKBucket substitute codecommit',
123+
reason: 'CDK S3 Bucket for Ref',
124124
}
125125
]
126126
);

0 commit comments

Comments
 (0)