1 Resposta
- Mais recentes
- Mais votos
- Mais comentários
0
Hi,
Below is a sample code,
const AWS = require('aws-sdk');
const rdsDataService = new AWS.RDSDataService();
exports.handler = async (event, context) => {
// Set the SQL statement
const sql = 'SELECT * FROM my_table';
// Execute the SQL statement
const params = {
database: 'my_database',
resourceArn: 'arn:aws:rds:us-east-1:123456789012:cluster:my-cluster',
secretArn: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:my-secret',
sql: sql
};
const response = await rdsDataService.executeStatement(params).promise();
// Return the query results as a JSON string
const body = JSON.stringify(response.records);
const statusCode = 200;
return { statusCode, body };
};
Hope this helps
respondido há um ano
Conteúdo relevante
- AWS OFICIALAtualizada há 2 anos
- AWS OFICIALAtualizada há um ano
- AWS OFICIALAtualizada há 3 anos
- AWS OFICIALAtualizada há 2 anos
Hi Arun, thanks for the code example. This brings the same error:
since serverless v2 has no support for Data API. Hence, the need for code example using RDS proxy endpoint alongside secrets manager.
Thanks again!
Sure. can you try importing pg8000 to create a pg8000.connect object to connect to the DB. A code sample with teh same is below
import boto3 import pg8000
def lambda_handler(event, context): rds_data = boto3.client('rds-data') response = rds_data.execute_statement( resourceArn='arn:aws:rds:us-east-1:123456789012:cluster:my-db-cluster', secretArn='arn:aws:secretsmanager:us-east-1:123456789012:secret:my-db-secret', database='my-db-name', sql='SELECT * FROM my_table;' )
Try and let us know, if it works