Skip to content

Commit

Permalink
fix bootstrap function and update jsii
Browse files Browse the repository at this point in the history
  • Loading branch information
hrodmn committed Jan 3, 2025
1 parent b8c1b60 commit 78b635f
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 321 deletions.
24 changes: 14 additions & 10 deletions lib/database/PgBouncer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ export class PgBouncer extends Construct {
runtime: lambda.Runtime.NODEJS_20_X,
handler: "index.handler",
code: lambda.Code.fromInline(`
const AWS = require('aws-sdk');
const sm = new AWS.SecretsManager();
const { SecretsManagerClient, GetSecretValueCommand, PutSecretValueCommand } = require('@aws-sdk/client-secrets-manager');
const client = new SecretsManagerClient();
exports.handler = async (event) => {
console.log('Event:', JSON.stringify(event, null, 2));
Expand All @@ -196,21 +196,25 @@ export class PgBouncer extends Construct {
const instanceIp = event.ResourceProperties.instanceIp;
// Get the original secret value
const originalSecret = await sm.getSecretValue({
SecretId: '${props.database.secret.secretArn}'
}).promise();
const getSecretResponse = await client.send(
new GetSecretValueCommand({
SecretId: '${props.database.secret.secretArn}'
})
);
// Parse the secret string
const secretData = JSON.parse(originalSecret.SecretString);
const secretData = JSON.parse(getSecretResponse.SecretString);
// Update the host value with the PgBouncer instance IP
secretData.host = instanceIp;
// Put the modified secret value
await sm.putSecretValue({
SecretId: '${this.pgbouncerSecret.secretArn}',
SecretString: JSON.stringify(secretData)
}).promise();
await client.send(
new PutSecretValueCommand({
SecretId: '${this.pgbouncerSecret.secretArn}',
SecretString: JSON.stringify(secretData)
})
);
return {
PhysicalResourceId: '${this.pgbouncerSecret.secretArn}',
Expand Down
Loading

0 comments on commit 78b635f

Please sign in to comment.