-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into vite-app-polishing
- Loading branch information
Showing
24 changed files
with
14,880 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<head> | ||
<meta name="Momento Node.js Client Library Documentation" content="Node.js client software development kit for Momento Cache"> | ||
</head> | ||
<img src="https://docs.momentohq.com/img/logo.svg" alt="logo" width="400"/> | ||
|
||
[![project status](https://momentohq.github.io/standards-and-practices/badges/project-status-official.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md) | ||
[![project stability](https://momentohq.github.io/standards-and-practices/badges/project-stability-stable.svg)](https://github.com/momentohq/standards-and-practices/blob/main/docs/momento-on-github.md) | ||
|
||
<br> | ||
|
||
## Simple Get Lambda | ||
|
||
This repo contains an example lambda, built using AWS CDK, that repeatedly calls get on a Momento cache. | ||
|
||
The primary use is to provide a base for testing Momento performance in a lambda environment. The lambda creates a Momento client, and then calls get on a hard-coded key 100 times, with a 100ms wait between calls. The metric logging middleware is enabled, so detailed information about each call is logged. | ||
|
||
## Prerequisites | ||
|
||
- Node version 14 or higher is required | ||
- To get started with Momento you will need a Momento Auth Token. You can get one from the [Momento Console](https://console.gomomento.com). Check out the [getting started](https://docs.momentohq.com/getting-started) guide for more information on obtaining an auth token. | ||
|
||
## Deploying the Simple Get Lambda | ||
|
||
First make sure to start Docker and install the dependencies in the `lambda` directory, which is where the AWS Lambda code lives. | ||
|
||
```bash | ||
cd lambda/simple-get | ||
npm install | ||
``` | ||
|
||
The source code for the CDK application lives in the `infrastructure` directory. | ||
To build and deploy it you will first need to install the dependencies: | ||
|
||
```bash | ||
cd infrastructure | ||
npm install | ||
``` | ||
|
||
To deploy the CDK app you will need to have [configured your AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-authentication.html#cli-chap-authentication-precedence). | ||
|
||
You will also need a superuser token generated from the [Momento Console](https://console.gomomento.com). | ||
|
||
Then run: | ||
|
||
``` | ||
npm run cdk -- deploy --parameters MomentoAuthToken=<YOUR_MOMENTO_AUTH_TOKEN> | ||
``` | ||
|
||
The lambda does not set up a way to access itself externally, so to run it, you will have to go to MomentoSimpleGet in AWS Lambda and run a test. | ||
|
||
The lambda is set up to make get calls for the key 'key' in the cache 'cache' by default. It does not create a cache or write anything to that key. While it still may give useful latency information if it can't find a cache or key, creating them will let you test in a more realistic way. | ||
|
||
If you have the [Momento CLI](https://github.com/momentohq/momento-cli) installed, you can create a cache like this: | ||
|
||
```commandline | ||
momento cache create cache | ||
``` | ||
|
||
You can then set a value for the key: | ||
|
||
```commandline | ||
momento cache set key value | ||
``` | ||
|
||
You can edit [handler.ts](lambda/simple-get/handler.ts) to change the cache and key the lambda looks for. |
3 changes: 3 additions & 0 deletions
3
examples/nodejs/lambda-examples/simple-get/infrastructure/.eslintignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dist | ||
**/*.d.ts |
62 changes: 62 additions & 0 deletions
62
examples/nodejs/lambda-examples/simple-get/infrastructure/.eslintrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"plugin:import/recommended", | ||
"plugin:prettier/recommended", | ||
"plugin:node/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 12, | ||
"project": "./tsconfig.json" | ||
}, | ||
"plugins": ["@typescript-eslint"], | ||
"rules": { | ||
"semi": ["error", "always"], | ||
"import/no-extraneous-dependencies": ["error", {}], | ||
"node/no-unsupported-features/es-syntax": "off", | ||
"node/no-missing-import": [ | ||
"error", | ||
{ | ||
"tryExtensions": [".js", ".ts", ".json", ".node"] | ||
} | ||
], | ||
"prettier/prettier": "error", | ||
"block-scoped-var": "error", | ||
"eqeqeq": "error", | ||
"no-var": "error", | ||
"prefer-const": "error", | ||
"eol-last": "error", | ||
"prefer-arrow-callback": "error", | ||
"no-trailing-spaces": "error", | ||
"quotes": ["warn", "single", {"avoidEscape": true}], | ||
"no-restricted-properties": [ | ||
"error", | ||
{ | ||
"object": "describe", | ||
"property": "only" | ||
}, | ||
{ | ||
"object": "it", | ||
"property": "only" | ||
} | ||
], | ||
// async without await is often an error and in other uses it obfuscates | ||
// the intent of the developer. Functions are async when they want to await. | ||
"require-await": "error", | ||
"import/no-duplicates": "error" | ||
}, | ||
"settings": { | ||
"import/resolver": { | ||
"node": { | ||
"extensions": [".js", ".jsx", ".ts", ".tsx"] | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
examples/nodejs/lambda-examples/simple-get/infrastructure/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
6
examples/nodejs/lambda-examples/simple-get/infrastructure/.npmignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
8 changes: 8 additions & 0 deletions
8
examples/nodejs/lambda-examples/simple-get/infrastructure/.prettierrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"bracketSpacing": false, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"arrowParens": "avoid", | ||
"printWidth": 120 | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
examples/nodejs/lambda-examples/simple-get/infrastructure/bin/infrastructure.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'source-map-support/register'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import {SimpleGetStack} from '../lib/simple-get-stack'; | ||
|
||
const app = new cdk.App(); | ||
new SimpleGetStack(app, 'MomentoSimpleGet', { | ||
/* 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 */ | ||
}); |
44 changes: 44 additions & 0 deletions
44
examples/nodejs/lambda-examples/simple-get/infrastructure/cdk.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"app": "npx ts-node --prefer-ts-exts bin/infrastructure.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 | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
examples/nodejs/lambda-examples/simple-get/infrastructure/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}; |
39 changes: 39 additions & 0 deletions
39
examples/nodejs/lambda-examples/simple-get/infrastructure/lib/simple-get-stack.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as path from 'path'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import {Construct} from 'constructs'; | ||
import * as lambda from 'aws-cdk-lib/aws-lambda'; | ||
import * as lambdaNodejs from 'aws-cdk-lib/aws-lambda-nodejs'; | ||
import * as secrets from 'aws-cdk-lib/aws-secretsmanager'; | ||
|
||
export class SimpleGetStack extends cdk.Stack { | ||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
const momentoAuthTokenParam = new cdk.CfnParameter(this, 'MomentoAuthToken', { | ||
type: 'String', | ||
description: 'The Momento Auth Token that will be used to read from the cache.', | ||
noEcho: true, | ||
}); | ||
|
||
const authTokenSecret = new secrets.Secret(this, 'MomentoSimpleGetAuthToken', { | ||
secretName: 'MomentoSimpleGetAuthToken', | ||
secretStringValue: new cdk.SecretValue(momentoAuthTokenParam.valueAsString), | ||
}); | ||
|
||
const getLambda = new lambdaNodejs.NodejsFunction(this, 'MomentoSimpleGet', { | ||
functionName: 'MomentoSimpleGet', | ||
runtime: lambda.Runtime.NODEJS_18_X, | ||
entry: path.join(__dirname, '../../lambda/simple-get/handler.ts'), | ||
projectRoot: path.join(__dirname, '../../lambda/simple-get'), | ||
depsLockFilePath: path.join(__dirname, '../../lambda/simple-get/package-lock.json'), | ||
handler: 'handler', | ||
timeout: cdk.Duration.seconds(30), | ||
memorySize: 128, | ||
environment: { | ||
MOMENTO_AUTH_TOKEN_SECRET_NAME: authTokenSecret.secretName, | ||
}, | ||
}); | ||
|
||
authTokenSecret.grantRead(getLambda); | ||
} | ||
} |
Oops, something went wrong.