Skip to content

Commit

Permalink
add worker lambda template that's deployed by AWS CDK (#395)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Ling <[email protected]>
  • Loading branch information
damienung1 and 72636c authored Apr 12, 2021
1 parent f496b80 commit 13b3bce
Show file tree
Hide file tree
Showing 20 changed files with 1,191 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/empty-shirts-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': minor
---

**template/lambda-sqs-worker-cdk:** Add new template
1 change: 1 addition & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
- greeter
- koa-rest-api
- lambda-sqs-worker
- lambda-sqs-worker-cdk
- oss-npm-package
- private-npm-package
steps:
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ This initialises a new directory and Git repository.
a message queue is employed between the source topic and the Lambda function,
and unprocessed events are sent to a dead-letter queue for manual triage.

- `lambda-sqs-worker-cdk`

An asynchronous [worker] built on [AWS Lambda] and deployed with [AWS CDK].

```text
SNS -> SQS (with a dead-letter queue) -> Lambda
```

Comes with configuration validation and infrastructure snapshot testing.

- `oss-npm-package`

A public npm package published via [semantic-release] pipeline.
Expand Down Expand Up @@ -197,6 +207,7 @@ This initialises a new directory and Git repository.
[serverless]: https://serverless.com/
[worker]: https://tech-strategy.ssod.skinfra.xyz/docs/v1/components.html#worker
[express]: https://expressjs.com/
[aws cdk]: https://tech-strategy.ssod.skinfra.xyz/docs/v1/technology.html#cdk

This script is interactive by default.
For unattended execution, pipe in JSON:
Expand Down
3 changes: 2 additions & 1 deletion config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"incremental": true,
"moduleResolution": "node"
"moduleResolution": "node",
"resolveJsonModule": true
},
"extends": "tsconfig-seek"
}
2 changes: 2 additions & 0 deletions src/cli/configure/analysis/__snapshots__/project.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ node_modules*/
},
".gitignore": Object {
"data": "# managed by skuba
.cdk.staging/
.idea/
.serverless/
.vscode/
cdk.out/
node_modules*/
/coverage*/
Expand Down
1 change: 1 addition & 0 deletions src/cli/init/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const TEMPLATE_PROMPT = new Select({
'greeter',
'koa-rest-api',
'lambda-sqs-worker',
'lambda-sqs-worker-cdk',
'oss-npm-package',
'private-npm-package',
'github →',
Expand Down
2 changes: 2 additions & 0 deletions template/base/_.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# managed by skuba
.cdk.staging/
.idea/
.serverless/
.vscode/
cdk.out/
node_modules*/

/coverage*/
Expand Down
61 changes: 61 additions & 0 deletions template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
dev-agent: &dev-agent
agents:
queue: <%- devBuildkiteQueueName %>

prod-agent: &prod-agent
agents:
queue: <%- prodBuildkiteQueueName %>

plugins: &plugins #alias for shared plugins
seek-oss/aws-sm#v2.3.1:
env:
NPM_TOKEN: 'arn:aws:secretsmanager:ap-southeast-2:987872074697:secret:npm/npm-read-token'
docker#v3.8.0:
volumes:
- /workdir/node_modules
- /workdir/lib
environment:
- NPM_TOKEN
seek-oss/docker-ecr-cache#v1.9.0:
build-args:
- NPM_TOKEN
cache-on:
- package.json
- yarn.lock

steps:
- label: ':yarn: :eslint: Lint and :jest: unit test'
<<: *dev-agent
plugins:
<<: *plugins
key: test
command:
- echo "--- Running yarn lint"
- yarn lint
- echo "--- Running yarn test :jest:"
- yarn test

- label: 'CDK Deploy Staging :shipit:'
<<: *dev-agent
plugins:
<<: *plugins
depends_on:
- test
command:
- echo "--- Running CDK deploy to staging"
- yarn deploy:dev
concurrency: 1
concurrency_group: '<%- repoName %>/deploy/dev'

- label: 'CDK Deploy Production :shipit:'
branches: 'master'
<<: *prod-agent
plugins:
<<: *plugins
depends_on:
- test
command:
- echo "--- Running CDK deploy to production"
- yarn deploy:prod
concurrency: 1
concurrency_group: '<%- repoName %>/deploy/prod'
22 changes: 22 additions & 0 deletions template/lambda-sqs-worker-cdk/.me
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
# https://codex.ssod.skinfra.xyz/docs

components:
'<%- repoName %>':
# TODO: supply system catalog information
# dependencies:
# - type: api
# key: SEEK-Jobs/???
# - type: datastore
# arn: arn:aws:dynamodb:us-east-1:123456789012:table/???
# - type: datastore
# key: infrastructure/???
deploy_target: Worker
# is_production_system: true
primary_technologies:
- AWS CDK
- AWS Lambda
- Buildkite
- skuba
- TypeScript
# scope: APAC
1 change: 1 addition & 0 deletions template/lambda-sqs-worker-cdk/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14
30 changes: 30 additions & 0 deletions template/lambda-sqs-worker-cdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Docker image history includes ARG values, so never target this stage directly
FROM node:14-alpine AS unsafe-dev-deps

WORKDIR /workdir

COPY package.json yarn.lock ./

ARG NPM_READ_TOKEN

RUN \
echo '//registry.npmjs.org/:_authToken=${NPM_READ_TOKEN}' > .npmrc && \
yarn install --frozen-lockfile --ignore-optional --non-interactive && \
yarn package && \
rm .npmrc

###

FROM node:14-alpine AS dev-deps

WORKDIR /workdir

COPY --from=unsafe-dev-deps /workdir .

###

FROM dev-deps AS build

COPY . .

RUN yarn build
25 changes: 25 additions & 0 deletions template/lambda-sqs-worker-cdk/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"app": "npx ts-node infra/index.ts",
"context": {
"@aws-cdk/core:enableStackNameDuplicates": "true",
"global": {
"appName": "<%- serviceName %>"
},
"dev": {
"workerLambda": {
"reservedConcurrency": 1,
"environment": {
"SOMETHING": "dev"
}
}
},
"prod": {
"workerLambda": {
"reservedConcurrency": 2,
"environment": {
"SOMETHING": "prod"
}
}
}
}
}
Loading

0 comments on commit 13b3bce

Please sign in to comment.