-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): publish lib as a Lambda Layer (#884)
* Add a cdk app capable of building and publishing Lambda Layer * add github action for e2e * add local layer construct npm package * disable fail fast * fix RUNTIME naming in matrix * fix tests * fix outputs export name * Add capability to pass package version to layer builder/publisher * Add initial doc * Add github workflows * add gitignore * fix install deps * pass layer name * make layer public and store details in ssm * fix e2e tests * fix context * remvove groups for tests * publish layer on release * fix account in doc * fix test deps * deploy to all region * fix account number for layer * fix unit tests * add install for layer deps in pr workflow * run unit test of layer publisher for supported node versions only * fix node version in doc * add node 16 to layer e2e * fix comments * fix doc * rename layer to TypeScript * take care of comments * remove layer from doc for now * remove pasted commenbt * chore(build): broke up pr workflow & measure package size (#1031) * chore: broke up pr workflow & measure package size * chore: explicitly set packages where to run cmds * fix: added missing dependency to examples/sam * added cache in workflow * chore: updated workflow + removed env var from command * chore: updated action version * fix: removed redundant env variable Co-authored-by: Florian Chazal <[email protected]> Co-authored-by: Andrea Amorosi <[email protected]>
- Loading branch information
1 parent
4a1c436
commit c3a20c6
Showing
23 changed files
with
12,761 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
name: Deploy layer to all regions | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
on: | ||
# Manual trigger | ||
workflow_dispatch: | ||
inputs: | ||
latest_published_version: | ||
description: "Latest npm published version to rebuild corresponding layer for, e.g. v1.0.2" | ||
default: "v1.0.2" | ||
required: true | ||
# Automatic trigger after release | ||
workflow_run: | ||
workflows: ["release"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
# Build layer by running cdk synth in layer-publisher directory and uploading cdk.out for deployment | ||
build-layer: | ||
runs-on: ubuntu-latest | ||
if: ${{ (github.event.workflow_run.conclusion == 'success') || (github.event_name == 'workflow_dispatch') }} | ||
defaults: | ||
run: | ||
working-directory: ./layer-publisher | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "16.12" | ||
- name: Set release notes tag | ||
run: | | ||
RELEASE_INPUT=${{ inputs.latest_published_version }} | ||
LATEST_TAG=$(git describe --tag --abbrev=0) | ||
RELEASE_TAG_VERSION=${RELEASE_INPUT:-$LATEST_TAG} | ||
echo "RELEASE_TAG_VERSION=${RELEASE_TAG_VERSION:1}" >> $GITHUB_ENV | ||
- name: install cdk and deps | ||
run: | | ||
npm install -g [email protected] | ||
cdk --version | ||
- name: install deps | ||
run: | | ||
npm ci | ||
- name: CDK build | ||
run: cdk synth --context PowerToolsPackageVersion=$RELEASE_TAG_VERSION -o cdk.out | ||
- name: zip output | ||
run: zip -r cdk.out.zip cdk.out | ||
- name: Archive CDK artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: cdk-layer-artefact | ||
path: layer-publisher/cdk.out.zip | ||
|
||
# Deploy layer to all regions in beta account | ||
deploy-beta: | ||
needs: | ||
- build-layer | ||
uses: ./.github/workflows/reusable_deploy_layer_stack.yml | ||
with: | ||
stage: "BETA" | ||
artefact-name: "cdk-layer-artefact" | ||
secrets: | ||
target-account-role: ${{ secrets.AWS_LAYERS_BETA_ROLE_ARN }} | ||
|
||
# Deploy layer to all regions in prod account | ||
deploy-prod: | ||
needs: | ||
- deploy-beta | ||
uses: ./.github/workflows/reusable_deploy_layer_stack.yml | ||
with: | ||
stage: "PROD" | ||
artefact-name: "cdk-layer-artefact" | ||
secrets: | ||
target-account-role: ${{ secrets.AWS_LAYERS_PROD_ROLE_ARN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
name: Deploy cdk stack | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
stage: | ||
required: true | ||
type: string | ||
artefact-name: | ||
required: true | ||
type: string | ||
secrets: | ||
target-account-role: | ||
required: true | ||
|
||
jobs: | ||
deploy-cdk-stack: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./layer-publisher | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
region: | ||
[ | ||
"af-south-1", | ||
"eu-central-1", | ||
"us-east-1", | ||
"us-east-2", | ||
"us-west-1", | ||
"us-west-2", | ||
"ap-east-1", | ||
"ap-south-1", | ||
"ap-northeast-1", | ||
"ap-northeast-2", | ||
"ap-southeast-1", | ||
"ap-southeast-2", | ||
"ca-central-1", | ||
"eu-west-1", | ||
"eu-west-2", | ||
"eu-west-3", | ||
"eu-south-1", | ||
"eu-north-1", | ||
"sa-east-1", | ||
"ap-southeast-3", | ||
"ap-northeast-3", | ||
"me-south-1", | ||
] | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v3 | ||
- name: aws credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-region: ${{ matrix.region }} | ||
role-to-assume: ${{ secrets.target-account-role }} | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "16.12" | ||
- name: install cdk and deps | ||
run: | | ||
npm install -g [email protected] | ||
cdk --version | ||
- name: install deps | ||
run: | | ||
npm ci | ||
- name: Download artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: ${{ inputs.artefact-name }} | ||
path: layer-publisher | ||
- name: unzip artefact | ||
run: unzip cdk.out.zip | ||
- name: CDK Deploy Layer | ||
run: cdk deploy --app cdk.out --context region=${{ matrix.region }} 'LayerPublisherStack' --require-approval never --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ jobs: | |
cd examples/cdk | ||
npm install ../../packages/**/dist/aws-lambda-powertools-* | ||
npm run test | ||
e2e-tests: | ||
package-e2e-tests: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write # needed to interact with GitHub's OIDC Token endpoint. | ||
|
@@ -68,6 +68,36 @@ jobs: | |
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_ARN_TO_ASSUME }} | ||
aws-region: eu-west-1 | ||
- name: "Run integration tests" | ||
- name: "Run packages integration tests" | ||
run: | | ||
RUNTIME=nodejs${{ matrix.version }}x npm run test:e2e -w packages/${{ matrix.package }} | ||
layer-e2e-tests: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write # needed to interact with GitHub's OIDC Token endpoint. | ||
contents: read | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: [12, 14, 16] | ||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v3 | ||
- name: "Use NodeJS 14" | ||
uses: actions/setup-node@v3 | ||
with: | ||
# Always use version 16 as we use TypeScript target es2020 | ||
node-version: 16 | ||
- name: "Install [email protected]" | ||
run: npm i -g npm@next-8 | ||
- name: "Configure AWS credentials" | ||
uses: aws-actions/[email protected] | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_ARN_TO_ASSUME }} | ||
aws-region: eu-west-1 | ||
- name: "Run layer integration tests" | ||
run: | | ||
npm ci --foreground-scripts | ||
RUNTIME=nodejs${{ matrix.version }}.x npm run test:e2e | ||
working-directory: layer-publisher | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.js | ||
!jest.config.js | ||
*.d.ts | ||
node_modules | ||
|
||
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.ts | ||
!*.d.ts | ||
|
||
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Lambda Powertools for TypeScript Layer Publisher | ||
|
||
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. | ||
|
||
# Usage | ||
|
||
```sh | ||
npm ci | ||
npm run cdk deploy | ||
``` | ||
|
||
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: | ||
```sh | ||
npm run cdk deploy -- --context PowerToolsPackageVersion='0.9.0' | ||
``` | ||
|
||
# Tests | ||
|
||
## Units | ||
|
||
```sh | ||
npm run test | ||
``` | ||
|
||
## E2E | ||
|
||
This will deploy and destroy several stacks in your AWS Account | ||
|
||
```sh | ||
npm run test:e2e | ||
``` | ||
|
||
PS: You can force | ||
* the lambda runtime to test with the RUNTIME env variable | ||
* the Powertools version with VERSION env variable | ||
```sh | ||
RUNTIME=node12.x VERSION=0.9.0 npm run test:e2e | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env node | ||
import 'source-map-support/register'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { LayerPublisherStack } from '../src/layer-publisher-stack'; | ||
|
||
const SSM_PARAM_LAYER_ARN = '/layers/powertools-layer-arn'; | ||
|
||
const app = new cdk.App(); | ||
new LayerPublisherStack(app, 'LayerPublisherStack', { | ||
powerToolsPackageVersion: app.node.tryGetContext('PowerToolsPackageVersion'), | ||
layerName: 'AWSLambdaPowertoolsTypeScript', | ||
ssmParameterLayerArn: SSM_PARAM_LAYER_ARN, | ||
}); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"app": "npx ts-node --prefer-ts-exts bin/layer-publisher.ts", | ||
"watch": { | ||
"include": [ | ||
"**" | ||
], | ||
"exclude": [ | ||
"README.md", | ||
"cdk*.json", | ||
"**/*.d.ts", | ||
"**/*.js", | ||
"tsconfig.json", | ||
"package*.json", | ||
"yarn.lock", | ||
"node_modules", | ||
"test" | ||
] | ||
}, | ||
"context": { | ||
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true, | ||
"@aws-cdk/core:stackRelativeExports": true, | ||
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true, | ||
"@aws-cdk/aws-lambda:recognizeVersionProps": true, | ||
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true, | ||
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, | ||
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, | ||
"@aws-cdk/core:target-partitions": [ | ||
"aws", | ||
"aws-cn" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
}; |
Oops, something went wrong.