-
Notifications
You must be signed in to change notification settings - Fork 156
feat(build): publish lib as a Lambda Layer #884
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
Changes from 33 commits
dcf724d
18ed8c9
6c8939e
76fa1d8
e063843
5a884ee
bc0a318
b057127
583a12f
e12dc75
022c517
e24df14
0f50311
01b91a8
e286e8d
cdf4e1f
b03413e
e7a254d
44f0728
8401da8
fb99afc
297907e
2ebe192
5d8ad97
e70e5c1
f509c6a
a2d1be5
1e58383
f8fee27
810e0dc
d07ccf9
c8465e2
c2b0f1b
4a1c436
fa2f59b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
ijemmy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- name: install cdk and deps | ||
run: | | ||
npm install -g aws-cdk@2.29.0 | ||
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 }} |
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 aws-cdk@2.29.0 | ||
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 | ||
ijemmy marked this conversation as resolved.
Show resolved
Hide resolved
|
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 |
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 |
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 | ||
``` |
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, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Putting this comment here because the file above called is a binary and doesn't allow comments: Do we need this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for now yes since my PR there is not merged yet : aws-samples/cdk-lambda-powertools-python-layer#52 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha, thanks for the explanation |
||
"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" | ||
] | ||
} | ||
} |
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' | ||
} | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.