Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adding examples that are currently hard-coded in dev docs #1428

Merged
merged 7 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ jobs:
npm run build
npm run validate-examples
popd
pushd examples/nodejs/webhooks
npm ci
npm run build
npm run validate-examples
popd
pushd examples/nodejs/storage
npm ci
npm run build
Expand Down Expand Up @@ -454,6 +459,10 @@ jobs:
npm ci
npm run build
popd
pushd examples/nodejs/aws/lambda-examples/webhooks/infrastructure
npm ci
npm run build
popd
pushd examples/nodejs/aws/lambda-examples/advanced-compression
# This example shows how to build and package a lambda function for a different target architecture,
# and thus it requires this `--force` flag.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
**/*.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"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",
"@typescript-eslint/switch-exhaustiveness-check": "error"
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
}
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
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"bracketSpacing": false,
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "avoid",
"printWidth": 120
}

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 {MomentoWebhookStack} from '../lib/momento-webhook-stack';

const app = new cdk.App();
new MomentoWebhookStack(app, 'MomentoWebhookStack', {
/* 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 */
});
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
}
}
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',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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';
import {CfnOutput} from 'aws-cdk-lib';

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

const momentoApiKeyParam = new cdk.CfnParameter(this, 'MomentoApiKey', {
type: 'String',
description: 'The Momento API key that will be used to read from the cache.',
noEcho: true,
});

const momentoSecretStringParam = new cdk.CfnParameter(this, 'MomentoSecretString', {
type: 'String',
description: 'The Momento Webhook Secret String that will be used to validate the caller',
noEcho: true,
});

const apiKeySecret = new secrets.Secret(this, 'MomentoWebhookHandlerApiKey', {
secretName: 'MomentoWebhookHandlerApiKey',
secretStringValue: new cdk.SecretValue(momentoApiKeyParam.valueAsString),
});

const secretStringSecret = new secrets.Secret(this, 'MomentoWebhookHandlerSecretString', {
secretName: 'MomentoWebhookHandlerSecretString',
secretStringValue: new cdk.SecretValue(momentoSecretStringParam.valueAsString),
});

const webhookHandlerLambda = new lambdaNodejs.NodejsFunction(this, 'MomentoWebhookHandler', {
functionName: 'MomentoWebhookHandler',
runtime: lambda.Runtime.NODEJS_18_X,
entry: path.join(__dirname, '../../lambda/webhook-handler/handler.ts'),
projectRoot: path.join(__dirname, '../../lambda/webhook-handler'),
depsLockFilePath: path.join(__dirname, '../../lambda/webhook-handler/package-lock.json'),
handler: 'handler',
timeout: cdk.Duration.seconds(30),
memorySize: 128,
environment: {
MOMENTO_API_KEY_SECRET_NAME: apiKeySecret.secretName,
THE_SIGNING_SECRET: secretStringSecret.secretName,
},
});

const serviceLambda = new lambdaNodejs.NodejsFunction(this, 'ServiceLambda', {
functionName: 'ServiceLambda',
runtime: lambda.Runtime.NODEJS_18_X,
entry: path.join(__dirname, '../../lambda/service-topics/handler.ts'),
projectRoot: path.join(__dirname, '../../lambda/service-topics'),
depsLockFilePath: path.join(__dirname, '../../lambda/service-topics/package-lock.json'),
handler: 'handler',
timeout: cdk.Duration.seconds(30),
memorySize: 128,
environment: {
MOMENTO_API_KEY_SECRET_NAME: apiKeySecret.secretName,
},
});

// 👇 Setup lambda url
const lambdaUrl = webhookHandlerLambda.addFunctionUrl({
authType: lambda.FunctionUrlAuthType.NONE,
});

apiKeySecret.grantRead(webhookHandlerLambda);
apiKeySecret.grantRead(serviceLambda);
secretStringSecret.grantRead(webhookHandlerLambda);

new CfnOutput(this, 'FunctionUrl ', {value: lambdaUrl.url});
}
}
Loading
Loading