Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f124a8b
fix: remove old nextjs example
yunusemreozdemir Jul 18, 2024
012aa9d
feat: create nextjs-app-router example
yunusemreozdemir Jul 18, 2024
a2de52c
feat: create nextjs-pages-router example
yunusemreozdemir Jul 18, 2024
03b7aa3
fix: remove old vercel functions related examples
yunusemreozdemir Jul 18, 2024
77b0a43
feat: create vercel-functions-app-router example
yunusemreozdemir Jul 18, 2024
8814d75
feat: create vercel-functions-pages-router example
yunusemreozdemir Jul 18, 2024
619ee3b
feat: update nodejs example
yunusemreozdemir Jul 18, 2024
502d9a4
feat: create fastapi example
yunusemreozdemir Jul 18, 2024
6eb39e6
feat: create vercel-python-runtime-django example
yunusemreozdemir Jul 18, 2024
0245b00
Merge branch 'main' of github.com:upstash/redis-js into DX-1036
yunusemreozdemir Aug 1, 2024
3af2a04
feat: create aws-cdk-python example
yunusemreozdemir Aug 1, 2024
7369ba1
feat: create aws-cdk-typescript example
yunusemreozdemir Aug 1, 2024
3a4b02b
feat: create aws-sam example
yunusemreozdemir Aug 1, 2024
4cef0f1
feat: create azure-functions example
yunusemreozdemir Aug 1, 2024
96e7a64
feat: create ion example
yunusemreozdemir Aug 1, 2024
dd940d7
feat: create serverless-framework example
yunusemreozdemir Aug 1, 2024
5d1c588
feat: create sst-v2 example
yunusemreozdemir Aug 1, 2024
5dfaae0
feat: update aws-lambda example
yunusemreozdemir Aug 1, 2024
e3185b1
feat: update google-cloud-functions example
yunusemreozdemir Aug 1, 2024
d74a9b2
feat: create terraform example
yunusemreozdemir Aug 1, 2024
c76e9fc
fix: update vercel functions tests
yunusemreozdemir Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Build
run: bun run build

nextjs-local:
vercel-functions-app-router-local:
needs:
- test

Expand All @@ -63,25 +63,25 @@ jobs:
run: |
bun install
bun add @upstash/redis@../../dist
working-directory: ./examples/nextjs
working-directory: ./examples/vercel-functions-app-router

- name: Build example
run: bun run build
working-directory: ./examples/nextjs
working-directory: ./examples/vercel-functions-app-router

- name: Start example
run: bun run start &
working-directory: ./examples/nextjs
working-directory: ./examples/vercel-functions-app-router
env:
NEXT_PUBLIC_UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }}
NEXT_PUBLIC_UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }}

- name: Test
run: bun test examples/nextjs/ci.test.ts
run: bun test examples/vercel-functions-app-router/ci.test.ts
env:
DEPLOYMENT_URL: http://localhost:3000

nextjs-edge-local:
vercel-functions-pages-router-local:
needs:
- test

Expand All @@ -105,26 +105,26 @@ jobs:
run: |
bun install
bun add @upstash/redis@../../dist
working-directory: ./examples/nextjs_edge
working-directory: ./examples/vercel-functions-pages-router

- name: Build example
run: bun run build
working-directory: ./examples/nextjs_edge
working-directory: ./examples/vercel-functions-pages-router

- name: Start example
run: bun run start & sleep 5
working-directory: ./examples/nextjs_edge
working-directory: ./examples/vercel-functions-pages-router
env:
NEXT_PUBLIC_UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }}
NEXT_PUBLIC_UPSTASH_REDIS_REST_TOKEN: ${{ secrets.UPSTASH_REDIS_REST_TOKEN }}

- name: Test
run: bun test examples/nextjs_edge/ci.test.ts
run: bun test examples/vercel-functions-pages-router/ci.test.ts
env:
DEPLOYMENT_URL: http://localhost:3000

nextjs-deployed:
concurrency: nextjs-deployed
vercel-functions-app-router-deployed:
concurrency: vercel-functions-app-router-deployed
runs-on: ubuntu-latest
needs:
- release
Expand All @@ -147,19 +147,19 @@ jobs:

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

- name: Test
run: bun test examples/nextjs/ci.test.ts
working-directory: examples/nextjs
run: bun test examples/vercel-functions-app-router/ci.test.ts
working-directory: examples/vercel-functions-app-router

nextjs-edge-deployed:
concurrency: nextjs-edge-deployed
vercel-functions-pages-router-deployed:
concurrency: vercel-functions-pages-router-deployed
runs-on: ubuntu-latest
needs:
- release
Expand All @@ -182,15 +182,15 @@ jobs:

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

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

deno-deployed:
concurrency: deno-deployed
Expand Down Expand Up @@ -572,8 +572,8 @@ jobs:
needs:
- nodejs-local
# - fastly-local - not working in ci for some reason, local is fine
- nextjs-local
- nextjs-edge-local
- vercel-functions-app-router-local
- vercel-functions-pages-router-local
- cloudflare-workers-with-typescript-local
- cloudflare-workers-local

Expand Down
8 changes: 8 additions & 0 deletions examples/aws-cdk-python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.js
!jest.config.js
*.d.ts
node_modules

# CDK asset staging directory
.cdk.staging
cdk.out
6 changes: 6 additions & 0 deletions examples/aws-cdk-python/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.ts
!*.d.ts

# CDK asset staging directory
.cdk.staging
cdk.out
36 changes: 36 additions & 0 deletions examples/aws-cdk-python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# AWS CDK TypeScript Example

### Prerequisites

- Complete all steps in [Getting started with the AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html)

### Project Setup

Clone the example and install dependencies

```shell
git clone https://github.com/upstash/redis-js.git
cd redis-js/examples/aws-cdk-python
npm install
```

### Database Setup

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.

```shell
export UPSTASH_REDIS_REST_URL=<YOUR_URL>
export UPSTASH_REDIS_REST_TOKEN=<YOUR_TOKEN>
```

### Deploy

Run in the top folder:

```shell
cdk synth
cdk bootstrap
cdk deploy
```

Visit the output url.
21 changes: 21 additions & 0 deletions examples/aws-cdk-python/bin/aws-cdk-python.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { AwsCdkPythonStack } from '../lib/aws-cdk-python-stack';

const app = new cdk.App();
new AwsCdkPythonStack(app, 'AwsCdkPythonStack', {
/* If you don't specify 'env', this stack will be environment-agnostic.
* Account/Region-dependent features and context lookups will not work,
* but a single synthesized template can be deployed anywhere. */

/* Uncomment the next line to specialize this stack for the AWS Account
* and Region that are implied by the current CLI configuration. */
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },

/* Uncomment the next line if you know exactly what Account and Region you
* want to deploy the stack to. */
// env: { account: '123456789012', region: 'us-east-1' },

/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
});
72 changes: 72 additions & 0 deletions examples/aws-cdk-python/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"app": "npx ts-node --prefer-ts-exts bin/aws-cdk-python.ts",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
"tsconfig.json",
"package*.json",
"yarn.lock",
"node_modules",
"test"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk/aws-redshift:columnId": true,
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
"@aws-cdk/aws-kms:aliasNameRef": true,
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false
}
}
8 changes: 8 additions & 0 deletions examples/aws-cdk-python/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
testEnvironment: 'node',
roots: ['<rootDir>/test'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
};
10 changes: 10 additions & 0 deletions examples/aws-cdk-python/lib/api/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from upstash_redis import Redis

redis = Redis.from_env()

def handler(event, context):
count = redis.incr('counter')
return {
'statusCode': 200,
'body': f'Counter: {count}'
}
1 change: 1 addition & 0 deletions examples/aws-cdk-python/lib/api/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
upstash-redis
36 changes: 36 additions & 0 deletions examples/aws-cdk-python/lib/aws-cdk-python-stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as path from 'path';

export class AwsCdkPythonStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const counterFunction = new lambda.Function(this, 'CounterFunction', {
code: lambda.Code.fromAsset(path.join(__dirname, 'api'), {
bundling: {
image: lambda.Runtime.PYTHON_3_9.bundlingImage,
command: [
'bash', '-c',
'pip install -r requirements.txt -t /asset-output && cp -au . /asset-output'
],
},
}),
runtime: lambda.Runtime.PYTHON_3_9,
handler: 'index.handler',
environment: {
UPSTASH_REDIS_REST_URL: process.env.UPSTASH_REDIS_REST_URL || '',
UPSTASH_REDIS_REST_TOKEN: process.env.UPSTASH_REDIS_REST_TOKEN || '',
},
});

const counterFunctionUrl = counterFunction.addFunctionUrl({
authType: lambda.FunctionUrlAuthType.NONE,
});

new cdk.CfnOutput(this, "counterFunctionUrlOutput", {
value: counterFunctionUrl.url,
})
}
}
Loading