Skip to content

Commit

Permalink
feat(examples): added sam example to workflows (#849)
Browse files Browse the repository at this point in the history
* feat: added sam example to workflows

* chore: added package-lock

* Modified symlink

* Fix import

* Added jest to sam

* Added jest to sam
  • Loading branch information
dreamorosi authored May 12, 2022
1 parent cabef3e commit 93f1c7b
Show file tree
Hide file tree
Showing 20 changed files with 9,881 additions and 56 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/on-merge-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ jobs:
# This installs all the dependencies of ./packages/*
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
run: npm ci --foreground-scripts
- name: Install example packages
# Since we are not managing the cdk examples with npm workspaces we install
- name: Install CDK example packages
# Since we are not managing the CDK examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/cdk
run: npm ci
run: npm ci
- name: Install SAM example packages
# Since we are not managing the SAM examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/sam
run: npm ci
- name: Run lint
run: npm run lerna-lint
- name: Run tests
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/on-release-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ jobs:
# This installs all the dependencies of ./packages/*
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
run: npm ci --foreground-scripts
- name: Install example packages
# Since we are not managing the cdk examples with npm workspaces we install
- name: Install CDK example packages
# Since we are not managing the CDK examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/cdk
run: npm ci
run: npm ci
- name: Install SAM example packages
# Since we are not managing the SAM examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/sam
run: npm ci
- name: Run lint
run: npm run lerna-lint
- name: Run tests
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/pr_lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ jobs:
# This installs all the dependencies of ./packages/*
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
run: npm ci --foreground-scripts
- name: Install example packages
# Since we are not managing the cdk examples with npm workspaces we install
- name: Install CDK example packages
# Since we are not managing the CDK examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/cdk
run: npm ci
run: npm ci
- name: Install SAM example packages
# Since we are not managing the SAM examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/sam
run: npm ci
- name: Run lint
run: npm run lerna-lint
- name: Run tests
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/run-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ jobs:
# This installs all the dependencies of ./packages/*
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
run: npm ci --foreground-scripts
- name: "Install example packages"
# Since we are not managing the cdk examples with npm workspaces we install
- name: Install CDK example packages
# Since we are not managing the CDK examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/cdk
run: npm ci
- name: Install SAM example packages
# Since we are not managing the SAM examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/sam
run: npm ci
- name: "Test packaging"
run: |
npm run lerna-package
Expand Down
8 changes: 7 additions & 1 deletion examples/cdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"name": "cdk-app",
"version": "0.8.1",
"author": {
"name": "Amazon Web Services",
"url": "https://aws.amazon.com"
},
"description": "This project contains source code and supporting files for a serverless application that you can deploy with CDK.",
"license": "MIT-0",
"bin": {
"cdk-app": "bin/cdk-app.js"
},
Expand Down Expand Up @@ -36,4 +42,4 @@
"constructs": "^10.0.82",
"source-map-support": "^0.5.16"
}
}
}
4 changes: 2 additions & 2 deletions examples/lambda-functions/get-by-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export const getByIdHandler = async (event: APIGatewayProxyEvent, context: Conte
throw new Error('SAMPLE_TABLE environment variable is not set');
}
if (!event.pathParameters) {
throw new Error('event does not contain pathParameters')
throw new Error('event does not contain pathParameters');
}
if (!event.pathParameters.id) {
throw new Error('PathParameter id is missing')
throw new Error('PathParameter id is missing');
}

const data = await docClient.get({
Expand Down
2 changes: 1 addition & 1 deletion examples/lambda-functions/put-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const putItemHandler = async (event: APIGatewayProxyEvent, context: Conte
throw new Error('SAMPLE_TABLE environment variable is not set');
}
if (!event.body) {
throw new Error('Event does not contain body')
throw new Error('Event does not contain body');
}

// Get id and name from the body of the request
Expand Down
16 changes: 8 additions & 8 deletions examples/sam/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This project contains source code and supporting files for a serverless applicat

This project includes the following files and folders:

- `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.
- `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.
- `events` - Invocation events that you can use to invoke the function.
- `template.yaml` - A template that defines the application's AWS resources.

Expand Down Expand Up @@ -110,7 +110,7 @@ Build your application with the `sam build` command.
sam build --beta-features
```
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.
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.
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.
Expand All @@ -130,12 +130,12 @@ curl http://localhost:3000/
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.
```yaml
Events:
HelloWorld:
Type: Api
Properties:
Path: /
Method: get
Events:
HelloWorld:
Type: Api
Properties:
Path: /
Method: get
```
## Fetch, tail, and filter Lambda function logs
Expand Down
8 changes: 8 additions & 0 deletions examples/sam/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
testEnvironment: 'node',
roots: ['<rootDir>/tests'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
};
Loading

0 comments on commit 93f1c7b

Please sign in to comment.