Skip to content

Instantly share code, notes, and snippets.

@mtimbs
mtimbs / babel.config.js
Last active February 27, 2020 14:27
default babel config serverless-typescript
module.exports = {
presets: [
[‘@babel/preset-env', { targets: { node: ‘current’ } }],
‘@babel/preset-typescript’,
],
};
@mtimbs
mtimbs / tsconfig.json
Last active February 27, 2020 14:28
default tsconfig configuration for serverless-typescript
{
"compilerOptions": {
"lib": ["es2017"],
"removeComments": true,
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"sourceMap": true,
"target": "es2017",
"outDir": "lib",
@mtimbs
mtimbs / .eslintrc.json
Last active February 27, 2020 14:29
default eslint configuration for serverless-typescript
{
"extends": [
"airbnb-base",
"plugin:jest/all",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:@typescript-eslint/recommended"
],
"plugins": [
@mtimbs
mtimbs / example.test.ts
Created February 27, 2020 14:29
example jest test to ensure jest is configured
describe('who tests the tests?', () => {
it('can run a test', () => {
expect.hasAssertions();
expect(1).toBe(1);
});
});
@mtimbs
mtimbs / package.json scripts
Last active February 27, 2020 14:33
default package.json scripts
"scripts": {
"test": "NODE_ENV=test ./node_modules/.bin/jest --ci --verbose",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"buildtest": "tsc --noEmit"
},
@mtimbs
mtimbs / handler.ts
Last active February 27, 2020 15:01
example API Gateway handler for serverless framework using module aliasing for imports
import { APIGatewayProxyHandler } from ‘aws-lambda';
import { echo } from ‘@queries/exampleQuery';
import 'source-map-support/register’;
export const hello: APIGatewayProxyHandler = async (event) => ({
statusCode: 200,
body: JSON.stringify({
message: echo(‘Module aliasing is really the best’),
input: event,
}, null, 2),
@mtimbs
mtimbs / base-IAM.json
Last active February 29, 2020 15:26
Base IAM permissions for deploying a serverless project
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"lambda:CreateFunction",
"lambda:ListVersionsByFunction",
"s3:CreateBucket",
@mtimbs
mtimbs / jest-dynamodb-config.js
Created March 10, 2020 13:51
basic config for jest and dynamodb offline
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
module.exports = async () => {
/* eslint-disable global-require */
const serverless = new (require('serverless'))();
await serverless.init();
const service = await serverless.variables.populateService();
const resources = service.resources.Resources;
const tables = Object.keys(resources)
@mtimbs
mtimbs / jest.config.js
Last active March 10, 2020 13:51
example jest config
module.exports = {
setupFiles: ['./tests/setup/setEnvironment.js'],
transform: {
'^.+\\.ts?$': 'babel-jest',
},
moduleNameMapper: {
'^@repositories/(.*)$': '<rootDir>/src/repositories/$1',
'^@clients/(.*)$': '<rootDir>/src/clients/$1',
'^@transformers/(.*)$': '<rootDir>/src/transformers/$1',
'^@src/(.*)$': '<rootDir>/src/$1',
@mtimbs
mtimbs / dynamoDBClient.ts
Created March 10, 2020 13:57
example base DynamoDB Client that will work for offline testing
import { DocumentClient } from 'aws-sdk/clients/dynamodb';
import DynamoDB from '@dazn/lambda-powertools-dynamodb-client';
/*
* This checks the environment and either outputs a raw DynamoDocumentClient for offline testing
* or it outputs the dazn-powertools DynamoDocumentClient that adds context and tracing
*/
export default ['test'].includes(process.env.NODE_ENV)
? new DocumentClient({
region: process.env.AWS_REGION,