Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add worker lambda template that's deployed by AWS CDK #395

Merged
merged 33 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d1c21c7
add worker lambda template that's deployed by AWS CDK
damienung1 Apr 1, 2021
1b3150d
update base template test snapshot
damienung1 Apr 1, 2021
c37e1e1
Update template/lambda-sqs-worker-cdk/.me
damienung1 Apr 2, 2021
f473201
relax build container version to major version only
damienung1 Apr 2, 2021
afaeb62
follow style recommendation for runtype imports
damienung1 Apr 2, 2021
1a7f7e1
remove unused package
damienung1 Apr 2, 2021
8b1ac25
remove maxWorkers flag from test step
damienung1 Apr 2, 2021
d62dd06
add @seek/logger, log hello world only
damienung1 Apr 2, 2021
acb8a44
remove CDK generated object that's not actually being used
damienung1 Apr 2, 2021
9f34eeb
Update template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml
damienung1 Apr 2, 2021
d8d3616
remove @types/jest as it's bundled in skuba
damienung1 Apr 2, 2021
d7286fe
remove code portion that's supposed to be populated by `skuba init`
damienung1 Apr 2, 2021
56dd771
update @types/node
damienung1 Apr 2, 2021
acac1f4
keep to default Dockerfile naming
damienung1 Apr 2, 2021
0b3ba19
Update README.md
damienung1 Apr 2, 2021
0a8a707
Update template/lambda-sqs-worker-cdk/infra/appStack.test.ts
damienung1 Apr 2, 2021
f0daac2
remove unnecessary shell out to bash
damienung1 Apr 2, 2021
a98046a
move CDK gitignores to base
damienung1 Apr 2, 2021
bf61a52
update snapshot test
damienung1 Apr 2, 2021
c788c18
Tweak base .gitignore
72636c Apr 3, 2021
5658f51
Update template/lambda-sqs-worker-cdk/.nvmrc
damienung1 Apr 3, 2021
44bd211
remove bash and git install step from the build docker image
damienung1 Apr 3, 2021
211232e
upstream resolveJsonModule
damienung1 Apr 3, 2021
5bcd4ff
remove esbuild
damienung1 Apr 5, 2021
5b8bcf5
Update README.md
damienung1 Apr 8, 2021
5021fc8
Update template/lambda-sqs-worker-cdk/src/app.ts
damienung1 Apr 8, 2021
238e850
prune configuration that needs to be managed in CDK context
damienung1 Apr 8, 2021
b15ccc2
fix ECR caching and packaging
damienung1 Apr 8, 2021
bd4ae58
remove redundant shebang
damienung1 Apr 8, 2021
ef8f9d4
Merge branch 'master' into cdk-lambda-sqs-worker-template
72636c Apr 12, 2021
357ac30
Create empty-shirts-film.md
72636c Apr 12, 2021
4619139
Add to CI
72636c Apr 12, 2021
c93dca8
Add to init prompt
72636c Apr 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem in line with the Technology Strategy: https://tech-strategy.ssod.skinfra.xyz/docs/v1/technology.html#lambda

I don't mind merging this, but can we kick off internal discussions over the merit of the CDK as a Lambda deployment tool?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly a misunderstanding on my part:
https://tech-strategy.ssod.skinfra.xyz/docs/v1/components.html#infrastructure

I read it to include Lambda workers. We're already using CDK to deploy workers in practice (among other things).

Copy link
Contributor

@etaoins etaoins Apr 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @72636c is referring to:

Lambda functions SHOULD be deployed using Serverless

This also repeated under the Worker section:

SHOULD deploy using Serverless

And the Serverless section:

https://serverless.com/

Serverless is our current default choice for packaging and deploying AWS Lambda functions.

Tech Strategy allowing CDK for infrastructure wouldn’t override the above guidance.

If your team has decided to deviate from SEEK’s Tech Strategy you could BYO GitHub template instead of including it in Skuba’s default templates.


```text
SNS -> SQS (with a dead-letter queue) -> Lambda
damienung1 marked this conversation as resolved.
Show resolved Hide resolved
```

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some thoughts on this pipeline, but the lambda-sqs-worker template is actually in a bad state itself. I'll raise a PR for that then we can discuss further.

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