Skip to content

Commit fa2f59b

Browse files
committed
Merge branch 'feat/layerPublisher' of github.com:awslabs/aws-lambda-powertools-typescript into feat/layerPublisher
2 parents 4a1c436 + c2b0f1b commit fa2f59b

23 files changed

+12761
-16
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ jobs:
6767
# the dependencies in a separate step
6868
working-directory: ./examples/cdk
6969
run: npm ci
70+
- name: Install Layer publisher app
71+
working-directory: ./layer-publisher
72+
run: npm ci
7073
- name: "Setup SAM"
7174
# We use an ad-hoc action so we can specify the SAM CLI version
7275
uses: aws-actions/setup-sam@v2

Diff for: .github/workflows/pr_lint_and_test.yml

+27-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ jobs:
4444
npm run build -w packages/commons
4545
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics
4646
- name: Lint
47-
run: npm run lint -w packages/logger -w packages/tracer -w packages/metrics
47+
run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics
4848
- name: Run unit tests
49-
run: npm t -w packages/logger -w packages/tracer -w packages/metrics
49+
run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics
5050
check-examples:
5151
runs-on: ubuntu-latest
5252
env:
@@ -79,4 +79,28 @@ jobs:
7979
- name: Install dependencies
8080
run: npm ci
8181
- name: Run tests
82-
run: npm t
82+
run: npm t
83+
check-layer-publisher:
84+
runs-on: ubuntu-latest
85+
env:
86+
NODE_ENV: dev
87+
defaults:
88+
run:
89+
working-directory: layer-publisher
90+
steps:
91+
- name: Checkout code
92+
uses: actions/checkout@v3
93+
- name: Setup NodeJS
94+
uses: actions/setup-node@v3
95+
with:
96+
node-version: 16
97+
cache: "npm"
98+
- name: Cache node modules
99+
id: cache-node-modules
100+
uses: actions/cache@v3
101+
with:
102+
path: "./layer-publisher/node_modules"
103+
# Use the combo between example, name, and SHA-256 hash of the layer-publisher lock files as cache key.
104+
key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/*/package-lock.json') }}
105+
- name: Install Layer publisher app
106+
run: npm ci

Diff for: .github/workflows/publish_layer.yaml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Deploy layer to all regions
2+
3+
permissions:
4+
id-token: write
5+
contents: read
6+
7+
on:
8+
# Manual trigger
9+
workflow_dispatch:
10+
inputs:
11+
latest_published_version:
12+
description: "Latest npm published version to rebuild corresponding layer for, e.g. v1.0.2"
13+
default: "v1.0.2"
14+
required: true
15+
# Automatic trigger after release
16+
workflow_run:
17+
workflows: ["release"]
18+
types:
19+
- completed
20+
21+
jobs:
22+
# Build layer by running cdk synth in layer-publisher directory and uploading cdk.out for deployment
23+
build-layer:
24+
runs-on: ubuntu-latest
25+
if: ${{ (github.event.workflow_run.conclusion == 'success') || (github.event_name == 'workflow_dispatch') }}
26+
defaults:
27+
run:
28+
working-directory: ./layer-publisher
29+
steps:
30+
- name: checkout
31+
uses: actions/checkout@v3
32+
with:
33+
fetch-depth: 0
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v3
36+
with:
37+
node-version: "16.12"
38+
- name: Set release notes tag
39+
run: |
40+
RELEASE_INPUT=${{ inputs.latest_published_version }}
41+
LATEST_TAG=$(git describe --tag --abbrev=0)
42+
RELEASE_TAG_VERSION=${RELEASE_INPUT:-$LATEST_TAG}
43+
echo "RELEASE_TAG_VERSION=${RELEASE_TAG_VERSION:1}" >> $GITHUB_ENV
44+
- name: install cdk and deps
45+
run: |
46+
npm install -g [email protected]
47+
cdk --version
48+
- name: install deps
49+
run: |
50+
npm ci
51+
- name: CDK build
52+
run: cdk synth --context PowerToolsPackageVersion=$RELEASE_TAG_VERSION -o cdk.out
53+
- name: zip output
54+
run: zip -r cdk.out.zip cdk.out
55+
- name: Archive CDK artifacts
56+
uses: actions/upload-artifact@v3
57+
with:
58+
name: cdk-layer-artefact
59+
path: layer-publisher/cdk.out.zip
60+
61+
# Deploy layer to all regions in beta account
62+
deploy-beta:
63+
needs:
64+
- build-layer
65+
uses: ./.github/workflows/reusable_deploy_layer_stack.yml
66+
with:
67+
stage: "BETA"
68+
artefact-name: "cdk-layer-artefact"
69+
secrets:
70+
target-account-role: ${{ secrets.AWS_LAYERS_BETA_ROLE_ARN }}
71+
72+
# Deploy layer to all regions in prod account
73+
deploy-prod:
74+
needs:
75+
- deploy-beta
76+
uses: ./.github/workflows/reusable_deploy_layer_stack.yml
77+
with:
78+
stage: "PROD"
79+
artefact-name: "cdk-layer-artefact"
80+
secrets:
81+
target-account-role: ${{ secrets.AWS_LAYERS_PROD_ROLE_ARN }}

Diff for: .github/workflows/reusable_deploy_layer_stack.yml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Deploy cdk stack
2+
3+
permissions:
4+
id-token: write
5+
contents: read
6+
7+
on:
8+
workflow_call:
9+
inputs:
10+
stage:
11+
required: true
12+
type: string
13+
artefact-name:
14+
required: true
15+
type: string
16+
secrets:
17+
target-account-role:
18+
required: true
19+
20+
jobs:
21+
deploy-cdk-stack:
22+
runs-on: ubuntu-latest
23+
defaults:
24+
run:
25+
working-directory: ./layer-publisher
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
region:
30+
[
31+
"af-south-1",
32+
"eu-central-1",
33+
"us-east-1",
34+
"us-east-2",
35+
"us-west-1",
36+
"us-west-2",
37+
"ap-east-1",
38+
"ap-south-1",
39+
"ap-northeast-1",
40+
"ap-northeast-2",
41+
"ap-southeast-1",
42+
"ap-southeast-2",
43+
"ca-central-1",
44+
"eu-west-1",
45+
"eu-west-2",
46+
"eu-west-3",
47+
"eu-south-1",
48+
"eu-north-1",
49+
"sa-east-1",
50+
"ap-southeast-3",
51+
"ap-northeast-3",
52+
"me-south-1",
53+
]
54+
steps:
55+
- name: checkout
56+
uses: actions/checkout@v3
57+
- name: aws credentials
58+
uses: aws-actions/configure-aws-credentials@v1
59+
with:
60+
aws-region: ${{ matrix.region }}
61+
role-to-assume: ${{ secrets.target-account-role }}
62+
- name: Setup Node.js
63+
uses: actions/setup-node@v3
64+
with:
65+
node-version: "16.12"
66+
- name: install cdk and deps
67+
run: |
68+
npm install -g [email protected]
69+
cdk --version
70+
- name: install deps
71+
run: |
72+
npm ci
73+
- name: Download artifact
74+
uses: actions/download-artifact@v3
75+
with:
76+
name: ${{ inputs.artefact-name }}
77+
path: layer-publisher
78+
- name: unzip artefact
79+
run: unzip cdk.out.zip
80+
- name: CDK Deploy Layer
81+
run: cdk deploy --app cdk.out --context region=${{ matrix.region }} 'LayerPublisherStack' --require-approval never --verbose

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

+32-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
cd examples/cdk
4141
npm install ../../packages/**/dist/aws-lambda-powertools-*
4242
npm run test
43-
e2e-tests:
43+
package-e2e-tests:
4444
runs-on: ubuntu-latest
4545
permissions:
4646
id-token: write # needed to interact with GitHub's OIDC Token endpoint.
@@ -68,6 +68,36 @@ jobs:
6868
with:
6969
role-to-assume: ${{ secrets.AWS_ROLE_ARN_TO_ASSUME }}
7070
aws-region: eu-west-1
71-
- name: "Run integration tests"
71+
- name: "Run packages integration tests"
7272
run: |
7373
RUNTIME=nodejs${{ matrix.version }}x npm run test:e2e -w packages/${{ matrix.package }}
74+
layer-e2e-tests:
75+
runs-on: ubuntu-latest
76+
permissions:
77+
id-token: write # needed to interact with GitHub's OIDC Token endpoint.
78+
contents: read
79+
strategy:
80+
fail-fast: false
81+
matrix:
82+
version: [12, 14, 16]
83+
steps:
84+
- name: "Checkout"
85+
uses: actions/checkout@v3
86+
- name: "Use NodeJS 14"
87+
uses: actions/setup-node@v3
88+
with:
89+
# Always use version 16 as we use TypeScript target es2020
90+
node-version: 16
91+
- name: "Install [email protected]"
92+
run: npm i -g npm@next-8
93+
- name: "Configure AWS credentials"
94+
uses: aws-actions/[email protected]
95+
with:
96+
role-to-assume: ${{ secrets.AWS_ROLE_ARN_TO_ASSUME }}
97+
aws-region: eu-west-1
98+
- name: "Run layer integration tests"
99+
run: |
100+
npm ci --foreground-scripts
101+
RUNTIME=nodejs${{ matrix.version }}.x npm run test:e2e
102+
working-directory: layer-publisher
103+

Diff for: README.md

+12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ Find the complete project's [documentation here](https://awslabs.github.io/aws-l
3333

3434
### Installation
3535

36+
You have 2 ways of consuming those utilities:
37+
* NPM modules
38+
* Lambda Layer
39+
40+
#### Lambda layers
41+
42+
The AWS Lambda Powertools for TypeScript utilities is packaged as a single [AWS Lambda Layer](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-concepts.html#gettingstarted-concepts-layer)
43+
44+
👉 [Installation guide for the **AWS Lambda Powertools for TypeScript** layer](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/#lambda-layer)
45+
46+
#### NPM modules
47+
3648
The AWS Lambda Powertools for TypeScript utilities follow a modular approach, similar to the official [AWS SDK v3 for JavaScript](https://github.com/aws/aws-sdk-js-v3).
3749
Each TypeScript utility is installed as standalone NPM package.
3850

Diff for: layer-publisher/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out

Diff for: layer-publisher/.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out

Diff for: layer-publisher/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Lambda Powertools for TypeScript Layer Publisher
2+
3+
This CDK app is meant to be used to publish Powertools for TypeScript Lambda Layer. It is composed of a single stack deploying the Layer into the target account.
4+
5+
# Usage
6+
7+
```sh
8+
npm ci
9+
npm run cdk deploy
10+
```
11+
12+
By default it will package the layer with the latest version publicly available but you can force the public version to use with `PowerToolsPackageVersion` context variable:
13+
```sh
14+
npm run cdk deploy -- --context PowerToolsPackageVersion='0.9.0'
15+
```
16+
17+
# Tests
18+
19+
## Units
20+
21+
```sh
22+
npm run test
23+
```
24+
25+
## E2E
26+
27+
This will deploy and destroy several stacks in your AWS Account
28+
29+
```sh
30+
npm run test:e2e
31+
```
32+
33+
PS: You can force
34+
* the lambda runtime to test with the RUNTIME env variable
35+
* the Powertools version with VERSION env variable
36+
```sh
37+
RUNTIME=node12.x VERSION=0.9.0 npm run test:e2e
38+
```

Diff for: layer-publisher/bin/layer-publisher.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
import 'source-map-support/register';
3+
import * as cdk from 'aws-cdk-lib';
4+
import { LayerPublisherStack } from '../src/layer-publisher-stack';
5+
6+
const SSM_PARAM_LAYER_ARN = '/layers/powertools-layer-arn';
7+
8+
const app = new cdk.App();
9+
new LayerPublisherStack(app, 'LayerPublisherStack', {
10+
powerToolsPackageVersion: app.node.tryGetContext('PowerToolsPackageVersion'),
11+
layerName: 'AWSLambdaPowertoolsTypeScript',
12+
ssmParameterLayerArn: SSM_PARAM_LAYER_ARN,
13+
});

Diff for: layer-publisher/[email protected]

18.5 KB
Binary file not shown.

Diff for: layer-publisher/cdk.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts bin/layer-publisher.ts",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"**/*.d.ts",
11+
"**/*.js",
12+
"tsconfig.json",
13+
"package*.json",
14+
"yarn.lock",
15+
"node_modules",
16+
"test"
17+
]
18+
},
19+
"context": {
20+
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
21+
"@aws-cdk/core:stackRelativeExports": true,
22+
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
23+
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
24+
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
25+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
26+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
27+
"@aws-cdk/core:target-partitions": [
28+
"aws",
29+
"aws-cn"
30+
]
31+
}
32+
}

Diff for: layer-publisher/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)