Skip to content

Commit 1b77a0a

Browse files
DX-1036: Revisit SDK Examples (#1196)
* fix: remove old nextjs example * feat: create nextjs-app-router example * feat: create nextjs-pages-router example * fix: remove old vercel functions related examples * feat: create vercel-functions-app-router example * feat: create vercel-functions-pages-router example * feat: update nodejs example * feat: create fastapi example * feat: create vercel-python-runtime-django example * feat: create aws-cdk-python example * feat: create aws-cdk-typescript example * feat: create aws-sam example * feat: create azure-functions example * feat: create ion example * feat: create serverless-framework example * feat: create sst-v2 example * feat: update aws-lambda example * feat: update google-cloud-functions example * feat: create terraform example * fix: update vercel functions tests
1 parent 90ae6b1 commit 1b77a0a

File tree

247 files changed

+20799
-1252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+20799
-1252
lines changed

.github/workflows/tests.yaml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Build
4040
run: bun run build
4141

42-
nextjs-local:
42+
vercel-functions-app-router-local:
4343
needs:
4444
- test
4545

@@ -63,25 +63,25 @@ jobs:
6363
run: |
6464
bun install
6565
bun add @upstash/redis@../../dist
66-
working-directory: ./examples/nextjs
66+
working-directory: ./examples/vercel-functions-app-router
6767

6868
- name: Build example
6969
run: bun run build
70-
working-directory: ./examples/nextjs
70+
working-directory: ./examples/vercel-functions-app-router
7171

7272
- name: Start example
7373
run: bun run start &
74-
working-directory: ./examples/nextjs
74+
working-directory: ./examples/vercel-functions-app-router
7575
env:
7676
NEXT_PUBLIC_UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }}
7777
NEXT_PUBLIC_UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }}
7878

7979
- name: Test
80-
run: bun test examples/nextjs/ci.test.ts
80+
run: bun test examples/vercel-functions-app-router/ci.test.ts
8181
env:
8282
DEPLOYMENT_URL: http://localhost:3000
8383

84-
nextjs-edge-local:
84+
vercel-functions-pages-router-local:
8585
needs:
8686
- test
8787

@@ -105,26 +105,26 @@ jobs:
105105
run: |
106106
bun install
107107
bun add @upstash/redis@../../dist
108-
working-directory: ./examples/nextjs_edge
108+
working-directory: ./examples/vercel-functions-pages-router
109109

110110
- name: Build example
111111
run: bun run build
112-
working-directory: ./examples/nextjs_edge
112+
working-directory: ./examples/vercel-functions-pages-router
113113

114114
- name: Start example
115115
run: bun run start & sleep 5
116-
working-directory: ./examples/nextjs_edge
116+
working-directory: ./examples/vercel-functions-pages-router
117117
env:
118118
NEXT_PUBLIC_UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }}
119119
NEXT_PUBLIC_UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }}
120120

121121
- name: Test
122-
run: bun test examples/nextjs_edge/ci.test.ts
122+
run: bun test examples/vercel-functions-pages-router/ci.test.ts
123123
env:
124124
DEPLOYMENT_URL: http://localhost:3000
125125

126-
nextjs-deployed:
127-
concurrency: nextjs-deployed
126+
vercel-functions-app-router-deployed:
127+
concurrency: vercel-functions-app-router-deployed
128128
runs-on: ubuntu-latest
129129
needs:
130130
- release
@@ -147,19 +147,19 @@ jobs:
147147

148148
- name: Deploy
149149
run: |
150-
pnpm --dir=examples/nextjs add @upstash/redis@${{needs.release.outputs.version}}
150+
pnpm --dir=examples/vercel-functions-app-router add @upstash/redis@${{needs.release.outputs.version}}
151151
DEPLOYMENT_URL=$(npx vercel --token=${{ secrets.VERCEL_TOKEN }})
152152
echo "DEPLOYMENT_URL=${DEPLOYMENT_URL}" >> $GITHUB_ENV
153153
env:
154154
VERCEL_ORG_ID: ${{secrets.VERCEL_TEAM_ID}}
155155
VERCEL_PROJECT_ID: "prj_pFFK1XgNIlnW014iiuqAIQmBBuZA"
156156

157157
- name: Test
158-
run: bun test examples/nextjs/ci.test.ts
159-
working-directory: examples/nextjs
158+
run: bun test examples/vercel-functions-app-router/ci.test.ts
159+
working-directory: examples/vercel-functions-app-router
160160

161-
nextjs-edge-deployed:
162-
concurrency: nextjs-edge-deployed
161+
vercel-functions-pages-router-deployed:
162+
concurrency: vercel-functions-pages-router-deployed
163163
runs-on: ubuntu-latest
164164
needs:
165165
- release
@@ -182,15 +182,15 @@ jobs:
182182

183183
- name: Deploy
184184
run: |
185-
pnpm --dir=examples/nextjs_edge add @upstash/redis@${{needs.release.outputs.version}}
185+
pnpm --dir=examples/vercel-functions-pages-router add @upstash/redis@${{needs.release.outputs.version}}
186186
DEPLOYMENT_URL=$(npx vercel --token=${{ secrets.VERCEL_TOKEN }})
187187
echo "DEPLOYMENT_URL=${DEPLOYMENT_URL}" >> $GITHUB_ENV
188188
env:
189189
VERCEL_ORG_ID: ${{secrets.VERCEL_TEAM_ID}}
190190
VERCEL_PROJECT_ID: "prj_bc5kMFz6ifbAaA7U3N86YSYqUUUI"
191191

192192
- name: Test
193-
run: bun test examples/nextjs_edge/ci.test.ts
193+
run: bun test examples/vercel-functions-pages-router/ci.test.ts
194194

195195
deno-deployed:
196196
concurrency: deno-deployed
@@ -572,8 +572,8 @@ jobs:
572572
needs:
573573
- nodejs-local
574574
# - fastly-local - not working in ci for some reason, local is fine
575-
- nextjs-local
576-
- nextjs-edge-local
575+
- vercel-functions-app-router-local
576+
- vercel-functions-pages-router-local
577577
- cloudflare-workers-with-typescript-local
578578
- cloudflare-workers-local
579579

examples/aws-cdk-python/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out

examples/aws-cdk-python/.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out

examples/aws-cdk-python/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# AWS CDK TypeScript Example
2+
3+
### Prerequisites
4+
5+
- Complete all steps in [Getting started with the AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html)
6+
7+
### Project Setup
8+
9+
Clone the example and install dependencies
10+
11+
```shell
12+
git clone https://github.com/upstash/redis-js.git
13+
cd redis-js/examples/aws-cdk-python
14+
npm install
15+
```
16+
17+
### Database Setup
18+
19+
Create a Redis database using [Upstash Console](https://console.upstash.com) or [Upstash CLI](https://github.com/upstash/cli) and export `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` to your environment.
20+
21+
```shell
22+
export UPSTASH_REDIS_REST_URL=<YOUR_URL>
23+
export UPSTASH_REDIS_REST_TOKEN=<YOUR_TOKEN>
24+
```
25+
26+
### Deploy
27+
28+
Run in the top folder:
29+
30+
```shell
31+
cdk synth
32+
cdk bootstrap
33+
cdk deploy
34+
```
35+
36+
Visit the output url.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
import 'source-map-support/register';
3+
import * as cdk from 'aws-cdk-lib';
4+
import { AwsCdkPythonStack } from '../lib/aws-cdk-python-stack';
5+
6+
const app = new cdk.App();
7+
new AwsCdkPythonStack(app, 'AwsCdkPythonStack', {
8+
/* If you don't specify 'env', this stack will be environment-agnostic.
9+
* Account/Region-dependent features and context lookups will not work,
10+
* but a single synthesized template can be deployed anywhere. */
11+
12+
/* Uncomment the next line to specialize this stack for the AWS Account
13+
* and Region that are implied by the current CLI configuration. */
14+
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
15+
16+
/* Uncomment the next line if you know exactly what Account and Region you
17+
* want to deploy the stack to. */
18+
// env: { account: '123456789012', region: 'us-east-1' },
19+
20+
/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
21+
});

examples/aws-cdk-python/cdk.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts bin/aws-cdk-python.ts",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"**/*.d.ts",
11+
"**/*.js",
12+
"tsconfig.json",
13+
"package*.json",
14+
"yarn.lock",
15+
"node_modules",
16+
"test"
17+
]
18+
},
19+
"context": {
20+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
21+
"@aws-cdk/core:checkSecretUsage": true,
22+
"@aws-cdk/core:target-partitions": [
23+
"aws",
24+
"aws-cn"
25+
],
26+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
27+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
28+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
29+
"@aws-cdk/aws-iam:minimizePolicies": true,
30+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
31+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
32+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
33+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
34+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
35+
"@aws-cdk/core:enablePartitionLiterals": true,
36+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
37+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
38+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
39+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
40+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
41+
"@aws-cdk/aws-route53-patters:useCertificate": true,
42+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
43+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
44+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
45+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
46+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
47+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
48+
"@aws-cdk/aws-redshift:columnId": true,
49+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
50+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
51+
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
52+
"@aws-cdk/aws-kms:aliasNameRef": true,
53+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
54+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
55+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
56+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
57+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
58+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
59+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
60+
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
61+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
62+
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
63+
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
64+
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
65+
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
66+
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
67+
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
68+
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
69+
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
70+
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false
71+
}
72+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
roots: ['<rootDir>/test'],
4+
testMatch: ['**/*.test.ts'],
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest'
7+
}
8+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from upstash_redis import Redis
2+
3+
redis = Redis.from_env()
4+
5+
def handler(event, context):
6+
count = redis.incr('counter')
7+
return {
8+
'statusCode': 200,
9+
'body': f'Counter: {count}'
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
upstash-redis
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Construct } from 'constructs';
3+
import * as lambda from 'aws-cdk-lib/aws-lambda';
4+
import * as path from 'path';
5+
6+
export class AwsCdkPythonStack extends cdk.Stack {
7+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
8+
super(scope, id, props);
9+
10+
const counterFunction = new lambda.Function(this, 'CounterFunction', {
11+
code: lambda.Code.fromAsset(path.join(__dirname, 'api'), {
12+
bundling: {
13+
image: lambda.Runtime.PYTHON_3_9.bundlingImage,
14+
command: [
15+
'bash', '-c',
16+
'pip install -r requirements.txt -t /asset-output && cp -au . /asset-output'
17+
],
18+
},
19+
}),
20+
runtime: lambda.Runtime.PYTHON_3_9,
21+
handler: 'index.handler',
22+
environment: {
23+
UPSTASH_REDIS_REST_URL: process.env.UPSTASH_REDIS_REST_URL || '',
24+
UPSTASH_REDIS_REST_TOKEN: process.env.UPSTASH_REDIS_REST_TOKEN || '',
25+
},
26+
});
27+
28+
const counterFunctionUrl = counterFunction.addFunctionUrl({
29+
authType: lambda.FunctionUrlAuthType.NONE,
30+
});
31+
32+
new cdk.CfnOutput(this, "counterFunctionUrlOutput", {
33+
value: counterFunctionUrl.url,
34+
})
35+
}
36+
}

0 commit comments

Comments
 (0)