Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cdk/lambdas/rssFetcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions cdk/lambdas/voteReconcile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions cdk/lib/cron-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"],
},
Expand All @@ -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"],
},
Expand Down
6 changes: 5 additions & 1 deletion cdk/lib/storage-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -174,6 +175,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"),
Expand Down
Loading