Skip to content

Commit 0c9ada5

Browse files
author
Jordi Macià
committed
Create initial project structure
1 parent ff97064 commit 0c9ada5

19 files changed

+961
-0
lines changed

typescript-test-samples/step-functions-local/.gitignore

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam
4+
5+
### Linux ###
6+
*~
7+
8+
# temporary files which can be created if a process still has a handle open of a deleted file
9+
.fuse_hidden*
10+
11+
# KDE directory preferences
12+
.directory
13+
14+
# Linux trash folder which might appear on any partition or disk
15+
.Trash-*
16+
17+
# .nfs files are created when an open file is removed but is still being accessed
18+
.nfs*
19+
20+
### Node ###
21+
# Logs
22+
logs
23+
*.log
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
lerna-debug.log*
28+
29+
# Diagnostic reports (https://nodejs.org/api/report.html)
30+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
31+
32+
# Runtime data
33+
pids
34+
*.pid
35+
*.seed
36+
*.pid.lock
37+
38+
# Directory for instrumented libs generated by jscoverage/JSCover
39+
lib-cov
40+
41+
# Coverage directory used by tools like istanbul
42+
coverage
43+
*.lcov
44+
45+
# nyc test coverage
46+
.nyc_output
47+
48+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
49+
.grunt
50+
51+
# Bower dependency directory (https://bower.io/)
52+
bower_components
53+
54+
# node-waf configuration
55+
.lock-wscript
56+
57+
# Compiled binary addons (https://nodejs.org/api/addons.html)
58+
build/Release
59+
60+
# Dependency directories
61+
node_modules/
62+
jspm_packages/
63+
64+
# TypeScript v1 declaration files
65+
typings/
66+
67+
# TypeScript cache
68+
*.tsbuildinfo
69+
70+
# Optional npm cache directory
71+
.npm
72+
73+
# Optional eslint cache
74+
.eslintcache
75+
76+
# Optional stylelint cache
77+
.stylelintcache
78+
79+
# Microbundle cache
80+
.rpt2_cache/
81+
.rts2_cache_cjs/
82+
.rts2_cache_es/
83+
.rts2_cache_umd/
84+
85+
# Optional REPL history
86+
.node_repl_history
87+
88+
# Output of 'npm pack'
89+
*.tgz
90+
91+
# Yarn Integrity file
92+
.yarn-integrity
93+
94+
# dotenv environment variables file
95+
.env
96+
.env.test
97+
.env*.local
98+
99+
# parcel-bundler cache (https://parceljs.org/)
100+
.cache
101+
.parcel-cache
102+
103+
# Next.js build output
104+
.next
105+
106+
# Nuxt.js build / generate output
107+
.nuxt
108+
dist
109+
110+
# Storybook build outputs
111+
.out
112+
.storybook-out
113+
storybook-static
114+
115+
# rollup.js default build output
116+
dist/
117+
118+
# Gatsby files
119+
.cache/
120+
# Comment in the public line in if your project uses Gatsby and not Next.js
121+
# https://nextjs.org/blog/next-9-1#public-directory-support
122+
# public
123+
124+
# vuepress build output
125+
.vuepress/dist
126+
127+
# Serverless directories
128+
.serverless/
129+
130+
# FuseBox cache
131+
.fusebox/
132+
133+
# DynamoDB Local files
134+
.dynamodb/
135+
136+
# TernJS port file
137+
.tern-port
138+
139+
# Stores VSCode versions used for testing VSCode extensions
140+
.vscode-test
141+
142+
# Temporary folders
143+
tmp/
144+
temp/
145+
146+
### OSX ###
147+
# General
148+
.DS_Store
149+
.AppleDouble
150+
.LSOverride
151+
152+
# Icon must end with two \r
153+
Icon
154+
155+
# Thumbnails
156+
._*
157+
158+
# Files that might appear in the root of a volume
159+
.DocumentRevisions-V100
160+
.fseventsd
161+
.Spotlight-V100
162+
.TemporaryItems
163+
.Trashes
164+
.VolumeIcon.icns
165+
.com.apple.timemachine.donotpresent
166+
167+
# Directories potentially created on remote AFP share
168+
.AppleDB
169+
.AppleDesktop
170+
Network Trash Folder
171+
Temporary Items
172+
.apdisk
173+
174+
### SAM ###
175+
# Ignore build directories for the AWS Serverless Application Model (SAM)
176+
# Info: https://aws.amazon.com/serverless/sam/
177+
# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html
178+
179+
**/.aws-sam
180+
181+
### Windows ###
182+
# Windows thumbnail cache files
183+
Thumbs.db
184+
Thumbs.db:encryptable
185+
ehthumbs.db
186+
ehthumbs_vista.db
187+
188+
# Dump file
189+
*.stackdump
190+
191+
# Folder config file
192+
[Dd]esktop.ini
193+
194+
# Recycle Bin used on file shares
195+
$RECYCLE.BIN/
196+
197+
# Windows Installer files
198+
*.cab
199+
*.msi
200+
*.msix
201+
*.msm
202+
*.msp
203+
204+
# Windows shortcuts
205+
*.lnk
206+
207+
# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
AWS_DEFAULT_REGION=AWS_REGION_OF_YOUR_AWS_RESOURCES
2+
AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY
3+
AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_KEY
4+
WAIT_TIME_SCALE=VALUE
5+
LAMBDA_ENDPOINT=VALUE
6+
BATCH_ENDPOINT=VALUE
7+
DYNAMODB_ENDPOINT=VALUE
8+
ECS_ENDPOINT=VALUE
9+
GLUE_ENDPOINT=VALUE
10+
SAGE_MAKER_ENDPOINT=VALUE
11+
SQS_ENDPOINT=VALUE
12+
SNS_ENDPOINT=VALUE
13+
STEP_FUNCTIONS_ENDPOINT=VALUE
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"data": {
3+
"firstname": "Jane",
4+
"lastname": "Doe",
5+
"identity": {
6+
"email": "[email protected]",
7+
"ssn": "123-45-6789"
8+
},
9+
"address": {
10+
"street": "123 Main St",
11+
"city": "Columbus",
12+
"state": "OH",
13+
"zip": "43219"
14+
},
15+
"comments": "I am glad to sign-up for this service. Looking forward to different options."
16+
}
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker run -d -p 8083:8083 --mount type=bind,readonly,source=/home/jomafe/serverless-test-samples/typescript-test-samples/step-functions-local/statemachine/test/MockConfigFile.json,destination=/home/StepFunctionsLocal/MockConfigFile.json -e SFN_MOCK_CONFIG="/home/StepFunctionsLocal/MockConfigFile.json" amazon/aws-stepfunctions-local
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"title": "Typescript Test Samples Starter Project",
3+
"description": "This project contains automated test samples for serverless applications written in TypeScript. The project includes techniques for executing tests including mocking and testing in the cloud.",
4+
"content_language": "English",
5+
"language": "TypeScript",
6+
"type": ["Unit","Integration"],
7+
"diagram": "/img/system-under-test.png",
8+
"framework": "SAM",
9+
"services": ["apigw", "lambda","dynamodb"],
10+
"git_repo_url": "https://github.com/aws-samples/serverless-test-samples",
11+
"pattern_source": "AWS",
12+
"pattern_detail_tabs": [
13+
{
14+
"title": "Application Code",
15+
"filepath": "/list-buckets/app.ts"
16+
},
17+
{
18+
"title": "Unit Tests - Mock",
19+
"filepath": "/list-buckets/tests/unit/list-buckets.test.ts"
20+
},
21+
{
22+
"title": "Integration Tests",
23+
"filepath": "/list-buckets/tests/integration/api.test.ts"
24+
}
25+
],
26+
"authors": [
27+
{
28+
"name": "Brian Krygsman",
29+
"image": "https://avatars.githubusercontent.com/u/3408210?v=4",
30+
"bio": "Senior Solutions Architect at AWS",
31+
"linkedin": "https://www.linkedin.com/in/brian-krygsman/",
32+
"twitter": "https://twitter.com/brnkrygs"
33+
}
34+
]
35+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.aws-sam
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
parserOptions: {
4+
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
5+
sourceType: "module"
6+
},
7+
extends: [
8+
"plugin:@typescript-eslint/recommended", // recommended rules from the @typescript-eslint/eslint-plugin
9+
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
10+
],
11+
rules: {
12+
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
13+
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
14+
}
15+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/*
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
semi: true,
3+
trailingComma: "all",
4+
singleQuote: true,
5+
printWidth: 120,
6+
tabWidth: 4
7+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: MIT-0
3+
4+
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
5+
import { S3Client, ListBucketsCommand } from '@aws-sdk/client-s3';
6+
7+
const region = process.env.AWS_REGION ?? 'us-east-1';
8+
const s3Client = new S3Client({ region: region });
9+
10+
/**
11+
*
12+
* Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
13+
* @param {Object} event - API Gateway Lambda Proxy Input Format
14+
*
15+
* Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
16+
* @returns {Object} object - API Gateway Lambda Proxy Output Format
17+
*
18+
*/
19+
export const listBucketsLambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
20+
try {
21+
console.log('Called with event', event);
22+
23+
const listBucketsOutput = await s3Client.send(new ListBucketsCommand({}));
24+
let bucketList = '';
25+
if (listBucketsOutput.Buckets) {
26+
bucketList = listBucketsOutput.Buckets?.map((bucket) => bucket.Name).join(' | ');
27+
}
28+
29+
console.log('Bucket list created');
30+
31+
return {
32+
statusCode: 200,
33+
body: bucketList,
34+
};
35+
} catch (error) {
36+
console.error('Error', error);
37+
return {
38+
statusCode: 500,
39+
body: '',
40+
};
41+
}
42+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property and type check, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
export default {
7+
projects: ['<rootDir>/jest.integration.config.ts', '<rootDir>/jest.unit.config.ts'],
8+
transform: {
9+
'^.+\\.ts?$': 'esbuild-jest',
10+
},
11+
clearMocks: true,
12+
collectCoverage: true,
13+
coverageDirectory: 'coverage',
14+
coverageProvider: 'v8',
15+
silent: true,
16+
testMatch: ['**/tests/unit/*.test.ts', '**/tests/integration/*.test.ts'],
17+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
displayName: 'integration',
3+
testMatch: ['**/tests/integration/*.test.ts'],
4+
transform: {
5+
'^.+\\.ts?$': 'esbuild-jest',
6+
},
7+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
displayName: 'unit',
3+
testMatch: ['**/tests/unit/*.test.ts'],
4+
transform: {
5+
'^.+\\.ts?$': 'esbuild-jest',
6+
},
7+
};

0 commit comments

Comments
 (0)