Skip to content

Commit cc7c203

Browse files
julianwoodclaude
andcommitted
fix: migrate 9 Fargate/AppRunner patterns from AWS SDK v2 to v3
Patterns migrated: - fargate-eventbridge-cdk → @aws-sdk/client-eventbridge - fargate-sns-cdk → @aws-sdk/client-sns - fargate-dynamodb-cdk → @aws-sdk/client-dynamodb + @aws-sdk/lib-dynamodb - fargate-sfn-cdk → @aws-sdk/client-sfn - fargate-aurora-serverless-cdk → @aws-sdk/client-rds-data - fargate-sns-sqs-cdk → @aws-sdk/client-sns + @aws-sdk/client-sqs - fargate-sqs-cdk → @aws-sdk/client-sqs - apprunner-cdk → removed unused aws-sdk dependency - aurora-serverless-global-db-cdk → @aws-sdk/client-secrets-manager Also upgrades Dockerfiles from node:14/16 to node:22, removes pm2, and cleans up devDependencies. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 613c2bc commit cc7c203

27 files changed

Lines changed: 184 additions & 249 deletions

File tree

apprunner-cdk/cdk/src/Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
FROM node:14-alpine
1+
FROM node:22-alpine AS build
22
WORKDIR /usr
33
COPY package.json ./
44
COPY tsconfig.json ./
55
COPY src ./src
66
RUN npm install
77
RUN npm run build
88

9-
FROM node:14-alpine
9+
FROM node:22-alpine
1010
WORKDIR /usr
1111
COPY package.json ./
12-
RUN npm install --only=production
13-
COPY --from=0 /usr/dist .
14-
RUN npm install pm2 -g
12+
RUN npm install --omit=dev
13+
COPY --from=build /usr/dist .
1514
EXPOSE 80
16-
CMD ["pm2-runtime","index.js"]
15+
CMD ["node","index.js"]

apprunner-cdk/cdk/src/package.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,17 @@
1111
"build": "tsc",
1212
"prestart": "npm run build",
1313
"start": "node .",
14-
"test": "echo \"Error: no test specified\" && exit 1",
15-
"lint": "eslint . --ext .ts",
16-
"lint:fix": "npm run lint -- --fix"
14+
"test": "echo \"Error: no test specified\" && exit 1"
1715
},
1816
"keywords": [],
1917
"author": "GlennChia",
2018
"license": "ISC",
2119
"dependencies": {
22-
"aws-sdk": "^2.1009.0",
23-
"express": "^4.17.1"
20+
"express": "^4.21.0"
2421
},
2522
"devDependencies": {
26-
"@types/express": "^4.17.13",
27-
"@types/node": "^16.11.0",
28-
"@typescript-eslint/eslint-plugin": "^5.2.0",
29-
"@typescript-eslint/parser": "^5.2.0",
30-
"eslint": "^9.39.2",
31-
"eslint-config-prettier": "^6.10.0",
32-
"eslint-plugin-prettier": "^4.0.0",
33-
"prettier": "^2.2.1",
34-
"typescript": "^4.4.4"
23+
"@types/express": "^4.17.21",
24+
"@types/node": "^22.0.0",
25+
"typescript": "^5.5.0"
3526
}
3627
}

apprunner-cdk/cdk/src/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import express from "express";
2-
import AWS from "aws-sdk";
32

43
const app = express();
54
const port = 80;
6-
AWS.config.update({ region: process.env.region });
75

86
app.use(express.urlencoded({ extended: false }));
97
app.use(express.json());
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
FROM --platform=linux/amd64 node:16-alpine
1+
FROM --platform=linux/amd64 node:22-alpine AS build
22
WORKDIR /usr
33
COPY package.json ./
44
COPY src ./src
5-
RUN npm install
6-
RUN npm install pg
5+
RUN npm install --omit=dev
76
COPY . .
87
EXPOSE 80
9-
CMD ["npm","start"]
8+
CMD ["node","src/index.js"]

aurora-serverless-global-db-cdk/fargate/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
"description": "Fargate ECS container to run an express app",
55
"main": "src/index.js",
66
"scripts": {
7-
"build": "tsc",
87
"start": "node src/index.js"
98
},
109
"author": "nihilson",
1110
"license": "ISC",
1211
"dependencies": {
13-
"express": "^4.18.2",
14-
"pg": "^8.11.3",
15-
"aws-sdk": "^2.1692.0"
12+
"@aws-sdk/client-secrets-manager": "^3.750.0",
13+
"express": "^4.21.0",
14+
"pg": "^8.11.3"
1615
}
1716
}

aurora-serverless-global-db-cdk/fargate/src/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,32 @@ const express = require("express");
22
const app = express();
33
const port = 80;
44

5-
var AWS = require('aws-sdk');
5+
const { SecretsManagerClient, GetSecretValueCommand } = require('@aws-sdk/client-secrets-manager');
66
const Pool = require('pg').Pool
77

8-
var client = new AWS.SecretsManager({
8+
const client = new SecretsManagerClient({
99
region: process.env.REGION
1010
});
1111

1212
var pool;
1313

14-
client.getSecretValue({ SecretId: 'aurora-serverless-global-db-secret' }, function (err, data) {
15-
if (err) {
16-
console.log(err, err.stack);
17-
}
18-
else {
19-
secretParams = JSON.parse(data.SecretString);
14+
(async () => {
15+
try {
16+
const response = await client.send(
17+
new GetSecretValueCommand({ SecretId: 'aurora-serverless-global-db-secret' })
18+
);
19+
const secretParams = JSON.parse(response.SecretString);
2020
pool = new Pool({
2121
user: secretParams.username,
2222
host: process.env.DB_HOST,
2323
database: 'sample',
2424
password: secretParams.password,
2525
port: process.env.DB_PORT
2626
});
27+
} catch (err) {
28+
console.log(err, err.stack);
2729
}
28-
});
30+
})();
2931

3032
app.use(express.urlencoded({ extended: false }));
3133
app.use(express.json());
@@ -109,4 +111,4 @@ app.use(errorHandler)
109111

110112
app.listen(port, () => {
111113
console.log(`server started at http://localhost:${port}`);
112-
});
114+
});
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
FROM node:14-alpine
1+
FROM node:22-alpine AS build
22
WORKDIR /usr
33
COPY package.json ./
44
COPY tsconfig.json ./
55
COPY src ./src
66
RUN npm install
77
RUN npm run build
88

9-
FROM node:14-alpine
9+
FROM node:22-alpine
1010
WORKDIR /usr
1111
COPY package.json ./
12-
RUN npm install --only=production
13-
COPY --from=0 /usr/dist .
14-
RUN npm install pm2 -g
12+
RUN npm install --omit=dev
13+
COPY --from=build /usr/dist .
1514
EXPOSE 80
16-
CMD ["pm2-runtime","index.js"]
15+
CMD ["node","index.js"]

fargate-aurora-serverless-cdk/cdk/src/package.json

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,18 @@
1111
"build": "tsc",
1212
"prestart": "npm run build",
1313
"start": "node .",
14-
"test": "echo \"Error: no test specified\" && exit 1",
15-
"lint": "eslint . --ext .ts",
16-
"lint:fix": "npm run lint -- --fix"
14+
"test": "echo \"Error: no test specified\" && exit 1"
1715
},
1816
"keywords": [],
1917
"author": "GlennChia",
2018
"license": "ISC",
2119
"dependencies": {
22-
"aws-sdk": "^2.1009.0",
23-
"express": "^4.17.1"
20+
"@aws-sdk/client-rds-data": "^3.700.0",
21+
"express": "^4.21.0"
2422
},
2523
"devDependencies": {
26-
"@types/express": "^4.17.13",
27-
"@types/node": "^16.11.0",
28-
"@typescript-eslint/eslint-plugin": "^5.2.0",
29-
"@typescript-eslint/parser": "^5.2.0",
30-
"eslint": "^9.39.2",
31-
"eslint-config-prettier": "^6.10.0",
32-
"eslint-plugin-prettier": "^4.0.0",
33-
"prettier": "^2.2.1",
34-
"typescript": "^4.4.4"
24+
"@types/express": "^4.17.21",
25+
"@types/node": "^22.10.0",
26+
"typescript": "^5.7.0"
3527
}
3628
}
Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
import express from "express";
2-
import AWS from "aws-sdk";
2+
import { RDSDataClient, ExecuteStatementCommand } from "@aws-sdk/client-rds-data";
33

44
const app = express();
55
const port = 80;
66

77
app.use(express.urlencoded({ extended: false }));
88
app.use(express.json());
99

10-
const rdsDataService = new AWS.RDSDataService();
10+
const rdsDataClient = new RDSDataClient({ region: process.env.region });
1111

1212
const SECRET_ARN = process.env.secretArn;
1313
const DB_CLUSTER_ARN = process.env.dbClusterArn;
1414
const DB_NAME = process.env.dbName;
1515

16-
let sqlParams = {
17-
secretArn: SECRET_ARN,
18-
resourceArn: DB_CLUSTER_ARN,
19-
database: DB_NAME,
20-
includeResultMetadata: true,
21-
sql: "",
22-
};
23-
2416
app.get("/", (req, res) => {
2517
res.status(200).send(`Hello Serverless Fargate! Integrating with Aurora Serverless Cluster ${DB_NAME} Database`);
2618
});
2719

2820
app.post("/createtable", async (req, res) => {
2921
const tableName = req.body.tableName;
3022
const sqlCreateTable = `CREATE TABLE IF NOT EXISTS ${tableName} (id INT AUTO_INCREMENT PRIMARY KEY, foo VARCHAR(128), bar VARCHAR(128));`;
31-
sqlParams["sql"] = sqlCreateTable;
3223

3324
try {
34-
const result = await rdsDataService.executeStatement(sqlParams).promise();
25+
const result = await rdsDataClient.send(
26+
new ExecuteStatementCommand({
27+
secretArn: SECRET_ARN,
28+
resourceArn: DB_CLUSTER_ARN,
29+
database: DB_NAME,
30+
includeResultMetadata: true,
31+
sql: sqlCreateTable,
32+
})
33+
);
3534
return res.status(200).send({
3635
body: "OK!",
3736
response: result,
@@ -43,10 +42,17 @@ app.post("/createtable", async (req, res) => {
4342

4443
app.get("/showtables", async (req, res) => {
4544
const sqlShowTables = "SHOW TABLES;";
46-
sqlParams["sql"] = sqlShowTables;
4745

4846
try {
49-
const result = await rdsDataService.executeStatement(sqlParams).promise();
47+
const result = await rdsDataClient.send(
48+
new ExecuteStatementCommand({
49+
secretArn: SECRET_ARN,
50+
resourceArn: DB_CLUSTER_ARN,
51+
database: DB_NAME,
52+
includeResultMetadata: true,
53+
sql: sqlShowTables,
54+
})
55+
);
5056
return res.status(200).send({
5157
body: "OK!",
5258
response: result.records,
@@ -57,6 +63,5 @@ app.get("/showtables", async (req, res) => {
5763
});
5864

5965
app.listen(port, () => {
60-
// tslint:disable-next-line:no-console
6166
console.log(`server started at http://localhost:${port}`);
6267
});
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
FROM node:14-alpine
1+
FROM node:22-alpine AS build
22
WORKDIR /usr
33
COPY package.json ./
44
COPY tsconfig.json ./
55
COPY src ./src
66
RUN npm install
77
RUN npm run build
88

9-
FROM node:14-alpine
9+
FROM node:22-alpine
1010
WORKDIR /usr
1111
COPY package.json ./
12-
RUN npm install --only=production
13-
COPY --from=0 /usr/dist .
14-
RUN npm install pm2 -g
12+
RUN npm install --omit=dev
13+
COPY --from=build /usr/dist .
1514
EXPOSE 80
16-
CMD ["pm2-runtime","index.js"]
15+
CMD ["node","index.js"]

0 commit comments

Comments
 (0)