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

Commit

Permalink
Cluster v2 and Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Sep 17, 2024
1 parent 6a0f6b5 commit 2ab601e
Show file tree
Hide file tree
Showing 17 changed files with 2,414 additions and 64 deletions.
7 changes: 6 additions & 1 deletion examples/aws-cluster/sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
/* This file is auto-generated by SST. Do not edit. */
/* tslint:disable */
/* eslint-disable */
import "sst"
export {}
declare module "sst" {
export interface Resource {
"MyBucket": {
"name": string
"type": "sst.aws.Bucket"
}
"MyService": {
"service": string
"type": "sst.aws.Service"
"url": string
}
"MyVpc": {
"type": "sst.aws.Vpc"
}
}
}
export {}
3 changes: 1 addition & 2 deletions examples/aws-cluster/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ export default $config({
public: true,
});

const vpc = new sst.aws.Vpc("MyVpc", { nat: "managed" });
const vpc = new sst.aws.Vpc("MyVpc");

const cluster = new sst.aws.Cluster("MyCluster", { vpc });

cluster.addService("MyService", {
public: {
ports: [{ listen: "80/http" }],
Expand Down
30 changes: 30 additions & 0 deletions examples/aws-redis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Cluster } from "ioredis";
import { Resource } from "sst";

const client = new Cluster(
[
{
host: Resource.MyRedis.host,
port: Resource.MyRedis.port,
},
],
{
redisOptions: {
tls: {
checkServerIdentity: () => undefined,
},
username: Resource.MyRedis.username,
password: Resource.MyRedis.password,
},
}
);

export async function handler() {
await client.set("foo", `bar-${Date.now()}`);
return {
statusCode: 200,
body: JSON.stringify({
foo: await client.get("foo"),
}),
};
}
19 changes: 19 additions & 0 deletions examples/aws-redis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "aws-redis",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"deploy": "go run ../../cmd/sst deploy",
"remove": "go run ../../cmd/sst remove",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ioredis": "^5.4.1",
"sst": "latest"
}
}
25 changes: 25 additions & 0 deletions examples/aws-redis/sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* 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
}
"MyRedis": {
"clusterArn": string
"host": string
"password": string
"port": number
"type": "sst.aws.Redis"
"username": string
}
"MyVpc": {
"type": "sst.aws.Vpc"
}
}
}
26 changes: 26 additions & 0 deletions examples/aws-redis/sst.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <reference path="./.sst/platform/config.d.ts" />

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

return {
app: app.url,
};
},
});
Loading

0 comments on commit 2ab601e

Please sign in to comment.