Skip to content

ExecuteStatement

Source: src/AWS/RDSData/ExecuteStatement.ts

Runtime binding for rds-data:ExecuteStatement — run a SQL statement against an Aurora cluster over the HTTP Data API (no VPC attachment or database socket required).

Bind it to a DBCluster (with the Data API enabled via enableHttpEndpoint: true) and the Secrets Manager secret holding the database credentials. The cluster ARN, secret ARN, and database name are injected automatically, and the function is granted rds-data:ExecuteStatement plus secretsmanager:GetSecretValue on the secret. Provide the implementation with Effect.provide(AWS.RDSData.ExecuteStatementHttp).

Query with Named Parameters

export default MyFunction.make(
{ main: import.meta.url, functionUrl: true },
Effect.gen(function* () {
const db = yield* AWS.RDS.Aurora("AppDb", {
subnetIds: [subnetA.subnetId, subnetB.subnetId],
securityGroupIds: [dbSecurityGroup.groupId],
});
// init — bind the operation to the cluster + admin secret
const executeStatement = yield* AWS.RDSData.ExecuteStatement(db.cluster, {
secret: db.secret,
database: "app",
});
return {
fetch: Effect.gen(function* () {
// runtime — parameterized SQL over the Data API
const result = yield* executeStatement({
sql: "SELECT id, title FROM todos WHERE id = :id",
parameters: [{ name: "id", value: { longValue: 1 } }],
});
return yield* HttpServerResponse.json({ records: result.records ?? [] });
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(AWS.RDSData.ExecuteStatementHttp)),
);

Write Inside a Transaction

// pass a transactionId from AWS.RDSData.BeginTransaction to make the
// statement part of that transaction
yield* executeStatement({
sql: "INSERT INTO todos (id, title) VALUES (:id, :title)",
parameters: [
{ name: "id", value: { longValue: 42 } },
{ name: "title", value: { stringValue: "ship it" } },
],
transactionId: tx.transactionId,
});