From e45c117f156db3d40d6a747ba02008fc9bfce56d Mon Sep 17 00:00:00 2001 From: NiallJoeMaher Date: Tue, 17 Nov 2026 14:56:47 +0000 Subject: [PATCH 1/2] fix(cdk): connect the cron lambdas to RDS over verified TLS The RSS fetcher and vote-reconcile lambdas connected without TLS, which RDS has rejected since the Postgres 15 upgrade turned rds.force_ssl on, so both have failed on every run. They now use TLS and verify the server certificate against the RDS CA bundle that ships in the Lambda runtime. Verification needs a valid server certificate: the instance still served one issued under rds-ca-2019, which expired in August 2024. Move it to rds-ca-rsa2048-g1 (Postgres 15 rotates without a restart). --- cdk/lambdas/rssFetcher/index.ts | 3 +++ cdk/lambdas/voteReconcile/index.ts | 3 +++ cdk/lib/cron-stack.ts | 8 ++++++++ cdk/lib/storage-stack.ts | 3 +++ 4 files changed, 17 insertions(+) diff --git a/cdk/lambdas/rssFetcher/index.ts b/cdk/lambdas/rssFetcher/index.ts index c509de336..89a02b7ea 100644 --- a/cdk/lambdas/rssFetcher/index.ts +++ b/cdk/lambdas/rssFetcher/index.ts @@ -188,6 +188,9 @@ exports.handler = async function () { const client = new Client({ connectionString: DATABASE_URL, + // RDS rejects unencrypted connections (rds.force_ssl). The certificate is + // verified against the RDS CA bundle loaded via NODE_EXTRA_CA_CERTS. + ssl: true, }); await client.connect(); diff --git a/cdk/lambdas/voteReconcile/index.ts b/cdk/lambdas/voteReconcile/index.ts index 9991a08dc..0be01ec1d 100644 --- a/cdk/lambdas/voteReconcile/index.ts +++ b/cdk/lambdas/voteReconcile/index.ts @@ -58,6 +58,9 @@ exports.handler = async function () { const client = new Client({ connectionString: DATABASE_URL, + // RDS rejects unencrypted connections (rds.force_ssl). The certificate is + // verified against the RDS CA bundle loaded via NODE_EXTRA_CA_CERTS. + ssl: true, }); await client.connect(); diff --git a/cdk/lib/cron-stack.ts b/cdk/lib/cron-stack.ts index 66d051701..2593d6c7d 100644 --- a/cdk/lib/cron-stack.ts +++ b/cdk/lib/cron-stack.ts @@ -40,6 +40,12 @@ export class CronStack extends cdk.Stack { lambdaRole.addToPolicy(policy); + // Node 20+ Lambda runtimes no longer trust the Amazon RDS CAs by default, + // so the lambdas that connect to RDS over TLS load the bundled CA file. + const rdsCaEnvironment = { + NODE_EXTRA_CA_CERTS: "/var/runtime/ca-cert.pem", + }; + // RSS Feed Fetcher Lambda const rssFetcherFn = new NodejsFunction(this, "RSSFetcherLambda", { timeout: cdk.Duration.seconds(300), // 5 minutes for processing multiple feeds @@ -50,6 +56,7 @@ export class CronStack extends cdk.Stack { "/../lambdas/rssFetcher/package-lock.json", ), role: lambdaRole, + environment: rdsCaEnvironment, bundling: { nodeModules: ["@aws-sdk/client-ssm", "pg", "rss-parser"], }, @@ -72,6 +79,7 @@ export class CronStack extends cdk.Stack { "/../lambdas/voteReconcile/package-lock.json", ), role: lambdaRole, + environment: rdsCaEnvironment, bundling: { nodeModules: ["@aws-sdk/client-ssm", "pg"], }, diff --git a/cdk/lib/storage-stack.ts b/cdk/lib/storage-stack.ts index 9b1af584a..ef4208e7f 100644 --- a/cdk/lib/storage-stack.ts +++ b/cdk/lib/storage-stack.ts @@ -174,6 +174,9 @@ export class StorageStack extends cdk.Stack { databaseName: dbName, engine: rds.DatabaseInstanceEngine.postgres({ version: pgVersion }), parameterGroup, + // The instance was created under rds-ca-2019, whose server certificate + // expired in August 2024, so no client could verify the connection. + caCertificate: rds.CaCertificate.RDS_CA_RSA2048_G1, credentials: rds.Credentials.fromPassword( dbUsername, cdk.SecretValue.ssmSecure("/env/db/password", "1"), From e0c6e195c41febed4ac80a1e2d27f65a6098e940 Mon Sep 17 00:00:00 2001 From: NiallJoeMaher Date: Tue, 17 Nov 2026 15:17:20 +0000 Subject: [PATCH 2/2] fix(cdk): use an ASCII description for the RDS parameter group RDS rejects a parameter group description containing non-ASCII characters, so the stack could not deploy. --- cdk/lib/storage-stack.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cdk/lib/storage-stack.ts b/cdk/lib/storage-stack.ts index ef4208e7f..05143660f 100644 --- a/cdk/lib/storage-stack.ts +++ b/cdk/lib/storage-stack.ts @@ -162,7 +162,8 @@ export class StorageStack extends cdk.Stack { // connections must therefore carry `sslmode=require` in DATABASE_URL. const parameterGroup = new rds.ParameterGroup(this, "db-parameter-group", { engine: rds.DatabaseInstanceEngine.postgres({ version: pgVersion }), - description: "Codú Postgres 15 — force_ssl pinned on", + // ASCII only: RDS rejects a description with non-ASCII characters. + description: "Codu Postgres 15 - force_ssl pinned on", parameters: { "rds.force_ssl": "1", },