Skip to content

Commit 0126c66

Browse files
committed
feat: serverless
1 parent 8d42d93 commit 0126c66

31 files changed

+2808
-1628
lines changed

.github/scripts/pause.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
2-
# This script pauses AWS resources (ECS service and RDS Aurora cluster) in the current AWS account.
2+
# This script pauses AWS resources (ECS service) in the current AWS account.
3+
# Note: DynamoDB doesn't require pausing like RDS as it's pay-per-request
34

45
set -e # Exit on error
56

@@ -92,16 +93,13 @@ function pause_ecs_service() {
9293
# Main execution
9394
validate_args
9495

95-
# Check and pause Aurora cluster
96-
aurora_status=$(check_aurora_cluster)
97-
[ "$aurora_status" = "false" ] || echo "Aurora cluster status: $aurora_status"
98-
9996
# Check and pause ECS service
10097
ecs_status=$(check_ecs_cluster)
10198
[ "$ecs_status" = "INACTIVE" ] || echo "ECS cluster status: $ecs_status"
10299

103100
# Perform pause operations
104101
pause_ecs_service "$ecs_status"
105-
pause_aurora_cluster "$aurora_status"
102+
103+
echo "Pause completed. Note: DynamoDB doesn't require pausing as it uses pay-per-request billing."
106104

107105
echo "Pause operations completed"

.github/scripts/resume.sh

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
2-
# This script resumes AWS resources (ECS service and RDS Aurora cluster) in the specified AWS account.
2+
# This script resumes AWS resources (ECS service) in the specified AWS account.
3+
# Note: DynamoDB doesn't require resuming like RDS as it's always available
34

45
set -e # Exit on error
56

@@ -91,22 +92,11 @@ main() {
9192

9293
echo "Starting to resume resources for environment: ${env} with stack prefix: ${prefix}"
9394

94-
# Check DB cluster status
95-
local db_status=$(check_db_cluster "$prefix" "$env")
96-
97-
if [ "$db_status" == "not-found" ]; then
98-
echo "Skipping resume operation, DB cluster does not exist"
99-
return 0
100-
elif [ "$db_status" == "stopped" ]; then
101-
start_db_cluster "$prefix" "$env" || return 1
102-
else
103-
echo "DB cluster is not in a stopped state. Current state: $db_status"
104-
fi
105-
106-
# Resume ECS service
95+
# Resume ECS service (DynamoDB is always available)
10796
resume_ecs_service "$prefix" "$env"
10897

10998
echo "Resources have been resumed successfully"
99+
echo "Note: DynamoDB doesn't require resuming as it's always available with pay-per-request billing."
110100
}
111101

112102
# Parse and check arguments

.github/workflows/.builds.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
matrix:
2424
# Only building frontend containers to run PR based e2e tests
25-
package: [backend, migrations, frontend]
25+
package: [backend, frontend]
2626
timeout-minutes: 10
2727
steps:
2828
- uses: bcgov/action-builder-ghcr@v4.0.0

AWS-DEPLOY.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# How To Deploy to AWS using Terraform
2+
3+
## Prerequisites
4+
5+
1. BCGov AWS account/namespace.
6+
7+
## Steps to be taken in the console(UI) to setup the secret in github for terraform deployment
8+
9+
1. [Login to console via IDIR MFA](https://login.nimbus.cloud.gov.bc.ca/)
10+
2. Navigate to IAM, click on policies on left hand menu.
11+
3. Click on `Create policy` button and switch from visual to JSON then paste the below snippet
12+
13+
```json
14+
{
15+
"Version": "2012-10-17",
16+
"Statement": [
17+
{
18+
"Sid": "IAM",
19+
"Effect": "Allow",
20+
"Action": ["iam:*"],
21+
"Resource": ["*"]
22+
},
23+
{
24+
"Sid": "S3",
25+
"Effect": "Allow",
26+
"Action": ["s3:*"],
27+
"Resource": ["*"]
28+
},
29+
{
30+
"Sid": "Cloudfront",
31+
"Effect": "Allow",
32+
"Action": ["cloudfront:*"],
33+
"Resource": ["*"]
34+
},
35+
{
36+
"Sid": "ecs",
37+
"Effect": "Allow",
38+
"Action": ["ecs:*"],
39+
"Resource": "*"
40+
},
41+
{
42+
"Sid": "ecr",
43+
"Effect": "Allow",
44+
"Action": ["ecr:*"],
45+
"Resource": "*"
46+
},
47+
{
48+
"Sid": "Dynamodb",
49+
"Effect": "Allow",
50+
"Action": ["dynamodb:*"],
51+
"Resource": ["*"]
52+
},
53+
{
54+
"Sid": "APIgateway",
55+
"Effect": "Allow",
56+
"Action": ["apigateway:*"],
57+
"Resource": ["*"]
58+
},
59+
{
60+
"Sid": "Cloudwatch",
61+
"Effect": "Allow",
62+
"Action": ["cloudwatch:*"],
63+
"Resource": "*"
64+
},
65+
{
66+
"Sid": "EC2",
67+
"Effect": "Allow",
68+
"Action": ["ec2:*"],
69+
"Resource": "*"
70+
},
71+
{
72+
"Sid": "Autoscaling",
73+
"Effect": "Allow",
74+
"Action": ["autoscaling:*"],
75+
"Resource": "*"
76+
},
77+
{
78+
"Sid": "KMS",
79+
"Effect": "Allow",
80+
"Action": ["kms:*"],
81+
"Resource": "*"
82+
},
83+
{
84+
"Sid": "SecretsManager",
85+
"Effect": "Allow",
86+
"Action": ["secretsmanager:*"],
87+
"Resource": "*"
88+
},
89+
{
90+
"Sid": "CloudWatchLogs",
91+
"Effect": "Allow",
92+
"Action": ["logs:*"],
93+
"Resource": "*"
94+
},
95+
{
96+
"Sid": "WAF",
97+
"Effect": "Allow",
98+
"Action": ["wafv2:*"],
99+
"Resource": "*"
100+
},
101+
{
102+
"Sid": "ELB",
103+
"Effect": "Allow",
104+
"Action": ["elasticloadbalancing:*"],
105+
"Resource": "*"
106+
},
107+
{
108+
"Sid": "AppAutoScaling",
109+
"Effect": "Allow",
110+
"Action": ["application-autoscaling:*"],
111+
"Resource": "*"
112+
}
113+
114+
]
115+
}
116+
```
117+
4. Then create a role by clicking `create role` button and then selecting (custom trust policy radio button).
118+
5. Paste the below JSON after making modifications to set trust relationships of the role with your github repo(<repo_name> ex: bcgov/quickstart-aws-containers) .
119+
120+
```json
121+
{
122+
"Version": "2012-10-17",
123+
"Statement": [
124+
{
125+
"Effect": "Allow",
126+
"Principal": {
127+
"Federated": "arn:aws:iam::<account_number>:oidc-provider/token.actions.githubusercontent.com"
128+
},
129+
"Action": "sts:AssumeRoleWithWebIdentity",
130+
"Condition": {
131+
"StringLike": {
132+
"token.actions.githubusercontent.com:sub": "repo:<repo_name>:*"
133+
},
134+
"ForAllValues:StringEquals": {
135+
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
136+
"token.actions.githubusercontent.com:iss": "https://token.actions.githubusercontent.com"
137+
}
138+
}
139+
}
140+
]
141+
}
142+
```
143+
6. Click on Next button, then add the policies after searching for it and then enabling it by checking the checkbox.
144+
7. Finally give a role name for ex: `GHA_CI_CD` and then click on `create role` button.
145+
7. After the role is created copy the ARN, it would be like `arn:aws:iam::<account_number>:role/<role_name>` , `role_name` is what was created on step 4.
146+
8. Paste this value into github secrets, repository secret or environment secret based on your needs. The key to use is `AWS_DEPLOY_ROLE_ARN`
147+
9. Paste the license plate value( 6 alphanumeric characters ex: `ab9okj`) without the env as a repository secret. The Key to use is `AWS_LICENSE_PLATE`
148+
10. After this the github action workflows would be able to deploy the stack to AWS.

GHA.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,15 @@ The workflows in this repository are organized into three main categories:
198198
- Manual workflow dispatch with environment selection
199199
- Workflow call from other workflows
200200

201-
**Purpose**: Cost optimization by pausing resources outside of working hours.
201+
**Purpose**: Cost optimization by pausing ECS services outside of working hours. Note: DynamoDB doesn't require pausing as it uses pay-per-request billing.
202202

203203
**Inputs**:
204204
- `app_env`: Environment to pause resources for (dev, test, prod, or all)
205205

206206
**Details**:
207-
- Identifies resources that can be safely paused in specified environment(s)
207+
- Identifies ECS services that can be safely paused in specified environment(s)
208208
- Scales down ECS services to zero
209-
- Stops RDS clusters
209+
- Note: DynamoDB tables remain available as they use pay-per-request billing with no idle costs
210210
- Uses AWS CLI commands to pause specific services
211211
- Runs on a schedule to automatically pause resources
212212
- Can be targeted to specific environments (dev, test, prod)
@@ -218,15 +218,15 @@ The workflows in this repository are organized into three main categories:
218218
- Manual workflow dispatch with environment selection
219219
- Workflow call from other workflows (like PR deployment)
220220

221-
**Purpose**: Resume paused resources at the start of the working day or on-demand.
221+
**Purpose**: Resume paused ECS services at the start of the working day or on-demand. Note: DynamoDB is always available.
222222

223223
**Inputs**:
224224
- `app_env`: Environment to resume resources for (dev, test, prod, or all)
225225

226226
**Details**:
227-
- Starts RDS clusters in specified environment(s)
228227
- Scales ECS services back to their configured capacity
229228
- Ensures all services are in a ready state
229+
- Note: DynamoDB tables are always available and don't require resuming
230230
- Can be targeted to specific environments (dev, test, prod)
231231

232232
### `prune-env.yml`
@@ -257,7 +257,7 @@ The workflows use the following environment configurations:
257257
- Can be paused/resumed independently from other environments
258258
3. **Production (prod)**: Used for live production deployments via the release workflow
259259
- Uses a mix of FARGATE (base=1, 20%) and FARGATE_SPOT (80%) for reliability and cost-effectiveness
260-
- Database credentials stored and retrieved securely from AWS Secrets Manager
260+
- DynamoDB tables with deletion protection enabled for production environments
261261
- API Gateway with VPC Link for secure backend access
262262
- Requires strict environment approval for resource management operations
263263
- Can be excluded from automatic pause/resume schedules if needed for 24/7 availability

0 commit comments

Comments
 (0)