Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Postgres: new component using RDS Postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Oct 8, 2024
1 parent 6ef6756 commit eb61cda
Show file tree
Hide file tree
Showing 18 changed files with 1,047 additions and 278 deletions.
2 changes: 1 addition & 1 deletion cmd/sst/mosaic.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func CmdMosaic(c *cli.Cli) error {
}

if os.Getenv("SST_SERVER") != "" {
return util.NewReadableError(nil, "The dev command for this process does not look right. Check your dev script in package.json to make sure it is simply starting your process and not running `sst dev`. More info here: https://ion.sst.dev/docs/reference/cli/#dev")
return util.NewReadableError(nil, "The dev command for this process does not look right. Check your dev script in package.json to make sure it is simply starting your process and not running `sst dev`. More info here: https://sst.dev/docs/reference/cli/#dev")
}

p, err := c.InitProject()
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Examples

A collection of example SST apps. You can also [view these in our docs](https://ion.sst.dev/docs/examples/).
A collection of example SST apps. You can also [view these in our docs](https://sst.dev/docs/examples/).

## Generated Docs

Expand Down
21 changes: 21 additions & 0 deletions examples/aws-postgres/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pg from "pg";
import { Resource } from "sst";
const { Client } = pg;
const client = new Client({
user: Resource.MyDatabase.username,
password: Resource.MyDatabase.password,
database: Resource.MyDatabase.database,
host: Resource.MyDatabase.host,
port: Resource.MyDatabase.port,
});
await client.connect();

export async function handler() {
const res = await client.query("SELECT $1::text as message", [
"Hello world!",
]);
return {
statusCode: 200,
body: res.rows[0].message,
};
}
16 changes: 16 additions & 0 deletions examples/aws-postgres/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "aws-postgres",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"pg": "^8.13.0",
"sst": "latest"
}
}
26 changes: 26 additions & 0 deletions examples/aws-postgres/sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* This file is auto-generated by SST. Do not edit. */
/* tslint:disable */
/* eslint-disable */
import "sst"
export {}
declare module "sst" {
export interface Resource {
"MyApp": {
"name": string
"type": "sst.aws.Function"
"url": string
}
"MyPostgres": {
"database": string
"host": string
"password": string
"port": number
"type": "sst.aws.Postgres"
"username": string
}
"MyVpc": {
"bastion": string
"type": "sst.aws.Vpc"
}
}
}
37 changes: 37 additions & 0 deletions examples/aws-postgres/sst.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference path="./.sst/platform/config.d.ts" />

export default $config({
app(input) {
return {
name: "aws-postgres",
removal: input?.stage === "production" ? "retain" : "remove",
home: "aws",
};
},
async run() {
// NAT Gateways are required for Lambda functions
const vpc = new sst.aws.Vpc("MyVpc", { bastion: true });
const postgres = new sst.aws.Postgres("MyDatabase", {
vpc,
});
const app = new sst.aws.Function("MyApp", {
handler: "index.handler",
url: true,
link: [postgres],
nodejs: {
esbuild: {
external: ["pg"],
},
},
});

return {
app: app.url,
host: postgres.host,
port: postgres.port,
username: postgres.username,
password: postgres.password,
database: postgres.database,
};
},
});
3 changes: 2 additions & 1 deletion platform/src/auto/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ function addTransformationToRetainResourcesOnDelete() {
$app.removal === "retain-all" ||
($app.removal === "retain" &&
[
"aws:dynamodb/table:Table",
"aws:rds/instance:Instance",
"aws:s3/bucket:Bucket",
"aws:s3/bucketV2:BucketV2",
"aws:dynamodb/table:Table",
].includes(args.type))
) {
args.opts.retainOnDelete = true;
Expand Down
3 changes: 2 additions & 1 deletion platform/src/components/aws/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ export class Cluster extends Component {
super(__pulumiType, name, args, opts, {
_version,
_message: [
`There is a new version of "Cluster" that has breaking changes.`,
``,
`What changed:`,
` - In the old version, load balancers were deployed in public subnets, and services were deployed in private subnets. The VPC was required to have NAT gateways.`,
Expand All @@ -1111,7 +1112,7 @@ export class Cluster extends Component {
` - Set \`forceUpgrade: "v${_version}"\` on the "Cluster" component. Learn more https://sst.dev/docs/component/aws/cluster#forceupgrade`,
``,
`To continue using v${$cli.state.version[name]}:`,
` - Rename "Cluster" to "Cluster.v${$cli.state.version[name]}". Learn more about versioning - https://ion.sst.dev/docs/components/#versioning`,
` - Rename "Cluster" to "Cluster.v${$cli.state.version[name]}". Learn more about versioning - https://sst.dev/docs/components/#versioning`,
].join("\n"),
_forceUpgrade: args.forceUpgrade,
});
Expand Down
Loading

0 comments on commit eb61cda

Please sign in to comment.