Skip to content

Commit 93f1c7b

Browse files
authored
feat(examples): added sam example to workflows (#849)
* feat: added sam example to workflows * chore: added package-lock * Modified symlink * Fix import * Added jest to sam * Added jest to sam
1 parent cabef3e commit 93f1c7b

20 files changed

+9881
-56
lines changed

Diff for: .github/workflows/on-merge-to-main.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ jobs:
3434
# This installs all the dependencies of ./packages/*
3535
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
3636
run: npm ci --foreground-scripts
37-
- name: Install example packages
38-
# Since we are not managing the cdk examples with npm workspaces we install
37+
- name: Install CDK example packages
38+
# Since we are not managing the CDK examples with npm workspaces we install
3939
# the dependencies in a separate step
4040
working-directory: ./examples/cdk
41-
run: npm ci
41+
run: npm ci
42+
- name: Install SAM example packages
43+
# Since we are not managing the SAM examples with npm workspaces we install
44+
# the dependencies in a separate step
45+
working-directory: ./examples/sam
46+
run: npm ci
4247
- name: Run lint
4348
run: npm run lerna-lint
4449
- name: Run tests

Diff for: .github/workflows/on-release-prod.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ jobs:
3434
# This installs all the dependencies of ./packages/*
3535
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
3636
run: npm ci --foreground-scripts
37-
- name: Install example packages
38-
# Since we are not managing the cdk examples with npm workspaces we install
37+
- name: Install CDK example packages
38+
# Since we are not managing the CDK examples with npm workspaces we install
3939
# the dependencies in a separate step
4040
working-directory: ./examples/cdk
41-
run: npm ci
41+
run: npm ci
42+
- name: Install SAM example packages
43+
# Since we are not managing the SAM examples with npm workspaces we install
44+
# the dependencies in a separate step
45+
working-directory: ./examples/sam
46+
run: npm ci
4247
- name: Run lint
4348
run: npm run lerna-lint
4449
- name: Run tests

Diff for: .github/workflows/pr_lint_and_test.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ jobs:
2222
# This installs all the dependencies of ./packages/*
2323
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
2424
run: npm ci --foreground-scripts
25-
- name: Install example packages
26-
# Since we are not managing the cdk examples with npm workspaces we install
25+
- name: Install CDK example packages
26+
# Since we are not managing the CDK examples with npm workspaces we install
2727
# the dependencies in a separate step
2828
working-directory: ./examples/cdk
29-
run: npm ci
29+
run: npm ci
30+
- name: Install SAM example packages
31+
# Since we are not managing the SAM examples with npm workspaces we install
32+
# the dependencies in a separate step
33+
working-directory: ./examples/sam
34+
run: npm ci
3035
- name: Run lint
3136
run: npm run lerna-lint
3237
- name: Run tests

Diff for: .github/workflows/run-e2e-tests.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ jobs:
2020
# This installs all the dependencies of ./packages/*
2121
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
2222
run: npm ci --foreground-scripts
23-
- name: "Install example packages"
24-
# Since we are not managing the cdk examples with npm workspaces we install
23+
- name: Install CDK example packages
24+
# Since we are not managing the CDK examples with npm workspaces we install
2525
# the dependencies in a separate step
2626
working-directory: ./examples/cdk
2727
run: npm ci
28+
- name: Install SAM example packages
29+
# Since we are not managing the SAM examples with npm workspaces we install
30+
# the dependencies in a separate step
31+
working-directory: ./examples/sam
32+
run: npm ci
2833
- name: "Test packaging"
2934
run: |
3035
npm run lerna-package

Diff for: examples/cdk/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"name": "cdk-app",
33
"version": "0.8.1",
4+
"author": {
5+
"name": "Amazon Web Services",
6+
"url": "https://aws.amazon.com"
7+
},
8+
"description": "This project contains source code and supporting files for a serverless application that you can deploy with CDK.",
9+
"license": "MIT-0",
410
"bin": {
511
"cdk-app": "bin/cdk-app.js"
612
},
@@ -36,4 +42,4 @@
3642
"constructs": "^10.0.82",
3743
"source-map-support": "^0.5.16"
3844
}
39-
}
45+
}

Diff for: examples/lambda-functions/get-by-id.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ export const getByIdHandler = async (event: APIGatewayProxyEvent, context: Conte
5959
throw new Error('SAMPLE_TABLE environment variable is not set');
6060
}
6161
if (!event.pathParameters) {
62-
throw new Error('event does not contain pathParameters')
62+
throw new Error('event does not contain pathParameters');
6363
}
6464
if (!event.pathParameters.id) {
65-
throw new Error('PathParameter id is missing')
65+
throw new Error('PathParameter id is missing');
6666
}
6767

6868
const data = await docClient.get({

Diff for: examples/lambda-functions/put-item.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const putItemHandler = async (event: APIGatewayProxyEvent, context: Conte
5959
throw new Error('SAMPLE_TABLE environment variable is not set');
6060
}
6161
if (!event.body) {
62-
throw new Error('Event does not contain body')
62+
throw new Error('Event does not contain body');
6363
}
6464

6565
// Get id and name from the body of the request

Diff for: examples/sam/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This project contains source code and supporting files for a serverless applicat
44

55
This project includes the following files and folders:
66

7-
- `src/handlers` - Code for the application's Lambda function written in TypeScript. See "Prepare the project" below for instructions on how to copy the Lambda handler code here.
7+
- `src` - Code for the application's Lambda function written in TypeScript. See "Prepare the project" below for instructions on how to copy the Lambda handler code here.
88
- `events` - Invocation events that you can use to invoke the function.
99
- `template.yaml` - A template that defines the application's AWS resources.
1010

@@ -110,7 +110,7 @@ Build your application with the `sam build` command.
110110
sam build --beta-features
111111
```
112112

113-
The SAM CLI installs dependencies defined in `src/handlers/package.json`, compiles TypeScript with esbuild, creates a deployment package, and saves it in the `.aws-sam/build` folder.
113+
The SAM CLI installs dependencies defined in `package.json`, compiles TypeScript with esbuild, creates a deployment package, and saves it in the `.aws-sam/build` folder.
114114

115115
Test a single function by invoking it directly with a test event. An event is a JSON document that represents the input that the function receives from the event source. Test events are included in the `events` folder in this project.
116116

@@ -130,12 +130,12 @@ curl http://localhost:3000/
130130
The SAM CLI reads the application template to determine the API's routes and the functions that they invoke. The `Events` property on each function's definition includes the route and method for each path.
131131

132132
```yaml
133-
Events:
134-
HelloWorld:
135-
Type: Api
136-
Properties:
137-
Path: /
138-
Method: get
133+
Events:
134+
HelloWorld:
135+
Type: Api
136+
Properties:
137+
Path: /
138+
Method: get
139139
```
140140
141141
## Fetch, tail, and filter Lambda function logs

Diff for: examples/sam/jest.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
roots: ['<rootDir>/tests'],
4+
testMatch: ['**/*.test.ts'],
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest'
7+
}
8+
};

0 commit comments

Comments
 (0)