projen 0.76.5 → 0.76.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +46 -46
- package/README.md +38 -33
- package/lib/awscdk/auto-discover.js +5 -5
- package/lib/awscdk/awscdk-app-java.js +1 -1
- package/lib/awscdk/awscdk-app-py.js +1 -1
- package/lib/awscdk/awscdk-app-ts.js +1 -1
- package/lib/awscdk/awscdk-construct.js +2 -2
- package/lib/awscdk/awscdk-deps-java.js +1 -1
- package/lib/awscdk/awscdk-deps-js.js +1 -1
- package/lib/awscdk/awscdk-deps-py.js +1 -1
- package/lib/awscdk/awscdk-deps.js +1 -1
- package/lib/awscdk/cdk-config.js +1 -1
- package/lib/awscdk/cdk-tasks.js +1 -1
- package/lib/awscdk/integration-test.js +1 -1
- package/lib/awscdk/lambda-extension.js +1 -1
- package/lib/awscdk/lambda-function.js +2 -2
- package/lib/build/build-workflow.js +1 -1
- package/lib/cdk/auto-discover-base.js +2 -2
- package/lib/cdk/construct-lib.js +1 -1
- package/lib/cdk/integration-test-base.js +1 -1
- package/lib/cdk/jsii-docgen.js +1 -1
- package/lib/cdk/jsii-project.js +1 -1
- package/lib/cdk8s/auto-discover.js +2 -2
- package/lib/cdk8s/cdk8s-app-py.js +1 -1
- package/lib/cdk8s/cdk8s-app-ts.js +1 -1
- package/lib/cdk8s/cdk8s-construct.js +1 -1
- package/lib/cdk8s/cdk8s-deps-py.js +1 -1
- package/lib/cdk8s/cdk8s-deps.js +1 -1
- package/lib/cdk8s/integration-test.js +1 -1
- package/lib/cdktf/cdktf-construct.js +1 -1
- package/lib/circleci/circleci.js +1 -1
- package/lib/component.js +1 -1
- package/lib/dependencies.js +1 -1
- package/lib/dev-env.js +1 -1
- package/lib/docker-compose/docker-compose-service.js +1 -1
- package/lib/docker-compose/docker-compose.js +1 -1
- package/lib/file.js +3 -3
- package/lib/gitattributes.js +1 -1
- package/lib/github/actions-provider.js +1 -1
- package/lib/github/auto-approve.js +1 -1
- package/lib/github/auto-merge.js +1 -1
- package/lib/github/dependabot.js +1 -1
- package/lib/github/github-credentials.js +1 -1
- package/lib/github/github-project.js +1 -1
- package/lib/github/github.js +1 -1
- package/lib/github/mergify.js +1 -1
- package/lib/github/pr-template.js +1 -1
- package/lib/github/pull-request-lint.js +1 -1
- package/lib/github/stale.js +1 -1
- package/lib/github/task-workflow.js +1 -1
- package/lib/github/workflow-actions.js +1 -1
- package/lib/github/workflow-jobs.js +1 -1
- package/lib/github/workflows.js +1 -1
- package/lib/gitlab/configuration.js +1 -1
- package/lib/gitlab/gitlab-configuration.js +1 -1
- package/lib/gitlab/nested-configuration.js +1 -1
- package/lib/gitpod.js +1 -1
- package/lib/ignore-file.js +1 -1
- package/lib/ini.js +1 -1
- package/lib/java/java-project.js +1 -1
- package/lib/java/junit.js +1 -1
- package/lib/java/maven-compile.js +1 -1
- package/lib/java/maven-packaging.js +1 -1
- package/lib/java/maven-sample.js +1 -1
- package/lib/java/pom.js +1 -1
- package/lib/java/projenrc.js +1 -1
- package/lib/javascript/bundler.js +1 -1
- package/lib/javascript/eslint.js +1 -1
- package/lib/javascript/jest.js +4 -4
- package/lib/javascript/node-package.js +1 -1
- package/lib/javascript/node-project.d.ts +2 -1
- package/lib/javascript/node-project.js +11 -6
- package/lib/javascript/npm-config.js +1 -1
- package/lib/javascript/prettier.js +1 -1
- package/lib/javascript/projenrc.js +1 -1
- package/lib/javascript/typescript-config.js +2 -2
- package/lib/javascript/upgrade-dependencies.d.ts +1 -1
- package/lib/javascript/upgrade-dependencies.js +3 -3
- package/lib/json-patch.js +1 -1
- package/lib/json.js +1 -1
- package/lib/license.js +1 -1
- package/lib/logger.js +1 -1
- package/lib/makefile.js +1 -1
- package/lib/object-file.js +1 -1
- package/lib/project-build.js +1 -1
- package/lib/project.d.ts +4 -4
- package/lib/project.js +6 -6
- package/lib/projects.js +1 -1
- package/lib/projenrc-json.js +2 -2
- package/lib/projenrc.js +1 -1
- package/lib/python/pip.js +1 -1
- package/lib/python/poetry.js +2 -2
- package/lib/python/projenrc.js +1 -1
- package/lib/python/pytest-sample.js +1 -1
- package/lib/python/pytest.js +1 -1
- package/lib/python/python-project.js +1 -1
- package/lib/python/python-sample.js +1 -1
- package/lib/python/requirements-file.js +1 -1
- package/lib/python/setuppy.js +1 -1
- package/lib/python/setuptools.js +1 -1
- package/lib/python/venv.js +1 -1
- package/lib/readme.js +1 -1
- package/lib/release/publisher.js +1 -1
- package/lib/release/release-trigger.js +1 -1
- package/lib/release/release.js +1 -1
- package/lib/renovatebot.js +1 -1
- package/lib/sample-file.js +2 -2
- package/lib/semver.js +1 -1
- package/lib/source-code.js +1 -1
- package/lib/task-runtime.js +1 -1
- package/lib/task.js +1 -1
- package/lib/tasks.js +1 -1
- package/lib/testing.js +1 -1
- package/lib/textfile.js +1 -1
- package/lib/toml.js +1 -1
- package/lib/typescript/projenrc-ts.js +1 -1
- package/lib/typescript/projenrc.js +1 -1
- package/lib/typescript/typescript-typedoc.js +1 -1
- package/lib/typescript/typescript.js +3 -3
- package/lib/util.d.ts +1 -0
- package/lib/util.js +2 -1
- package/lib/version.js +2 -2
- package/lib/vscode/devcontainer.js +1 -1
- package/lib/vscode/extensions.js +1 -1
- package/lib/vscode/launch-config.js +1 -1
- package/lib/vscode/settings.js +1 -1
- package/lib/vscode/vscode.js +1 -1
- package/lib/web/next.js +3 -3
- package/lib/web/postcss.js +1 -1
- package/lib/web/react.js +4 -4
- package/lib/web/tailwind.js +1 -1
- package/lib/xmlfile.js +1 -1
- package/lib/yaml.js +1 -1
- package/package.json +1 -1
- package/.prettierignore +0 -1
- package/.prettierrc.json +0 -3
- package/docs/CNAME +0 -1
- package/docs/README.md +0 -28
- package/docs/api/API.md +0 -21296
- package/docs/awscdk-apps.md +0 -18
- package/docs/awscdk-construct.md +0 -195
- package/docs/awscdk.md +0 -377
- package/docs/build.md +0 -55
- package/docs/bundling.md +0 -30
- package/docs/cdk8s.md +0 -39
- package/docs/circleci.md +0 -87
- package/docs/components.md +0 -21
- package/docs/deps.md +0 -62
- package/docs/eject.md +0 -30
- package/docs/escape-hatches.md +0 -113
- package/docs/github.md +0 -155
- package/docs/gitlab.md +0 -67
- package/docs/java.md +0 -213
- package/docs/node.md +0 -150
- package/docs/programmatic-api.md +0 -56
- package/docs/publisher.md +0 -148
- package/docs/python.md +0 -169
- package/docs/releases.md +0 -191
- package/docs/subproject.md +0 -37
- package/docs/tasks.md +0 -211
- package/docs/typescript.md +0 -119
- package/logo/projen.svg +0 -211
- package/rfcs/github-project-settings.md +0 -95
- package/rfcs/project-creation-prompt.md +0 -95
- package/version.json +0 -3
package/docs/awscdk-apps.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# AWS CDK Applications
|
|
2
|
-
|
|
3
|
-
Project types: `awscdk-app-java`, `awscdk-app-py`, `awscdk-app-ts`.
|
|
4
|
-
|
|
5
|
-
## Deployment (NOT IMPLEMENTED YET)
|
|
6
|
-
|
|
7
|
-
CDK application projects produce complete cloud applications. When a commit is
|
|
8
|
-
merged into the default branch, the app is rolled out by the release workflow to
|
|
9
|
-
AWS environments.
|
|
10
|
-
|
|
11
|
-
Possible implementation:
|
|
12
|
-
- [Deployable Typescript AWS CDK App](https://github.com/AminFazlMondo/deployable-awscdk-app-ts)
|
|
13
|
-
|
|
14
|
-
## Dev Stage (NOT IMPLEMENTED YET)
|
|
15
|
-
|
|
16
|
-
Every app includes an instance of the application stage which can be deployed to
|
|
17
|
-
a development AWS account. This allows each developer to use their AWS account
|
|
18
|
-
as part of their development environment.
|
package/docs/awscdk-construct.md
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
# AWS CDK Construct Library
|
|
2
|
-
|
|
3
|
-
AWS CDK library projects produce artifacts with reusable constructs which can be
|
|
4
|
-
consumed by other AWS CDK libraries or apps. Library artifacts are published to
|
|
5
|
-
private or public package managers under a semantic version.
|
|
6
|
-
|
|
7
|
-
By default, for every commit to the default branch, a new version is released
|
|
8
|
-
(trunk-based development). This includes the following steps:
|
|
9
|
-
|
|
10
|
-
1. Compile, lint and test the code.
|
|
11
|
-
1. Use [JSII](https://github.com/aws/jsii) to produce library artifacts for all
|
|
12
|
-
target languages.
|
|
13
|
-
1. Determine the next minor/patch version based on [conventional
|
|
14
|
-
commits](https://www.conventionalcommits.org). Major versions must be
|
|
15
|
-
explicitly bumped to protect consumers against breaking changes.
|
|
16
|
-
1. A changelog entry is generated based on commit history.
|
|
17
|
-
1. Packages are published to all target package managers.
|
|
18
|
-
|
|
19
|
-
## Getting Started
|
|
20
|
-
|
|
21
|
-
Start like all projen projects:
|
|
22
|
-
|
|
23
|
-
```sh
|
|
24
|
-
npx projen new awscdk-construct
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Review the resulting .projenrc.js file and make changes as needed. The following are some specific areas
|
|
28
|
-
you may want to set explicitly.
|
|
29
|
-
|
|
30
|
-
## Module Metadata
|
|
31
|
-
|
|
32
|
-
These fields are your basic Node module setup:
|
|
33
|
-
|
|
34
|
-
```typescript
|
|
35
|
-
authorAddress: 'benisrae@amazon.com',
|
|
36
|
-
authorName: 'Elad Ben-Israel',
|
|
37
|
-
description: 'Watching your CDK apps since 2019',
|
|
38
|
-
name: 'cdk-watchful',
|
|
39
|
-
license: 'MIT',
|
|
40
|
-
repository: 'https://github.com/eladb/cdk-watchful.git',
|
|
41
|
-
keywords: ['cloudwatch', 'monitoring']
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
All are pretty standard setup and nothing CDK-specific at this point. The `keywords` automatically gets 'cdk' so you don't
|
|
45
|
-
need to specify it.
|
|
46
|
-
|
|
47
|
-
## Dependencies
|
|
48
|
-
|
|
49
|
-
### Depending on AWS CDK modules
|
|
50
|
-
|
|
51
|
-
Next are getting CDK dependencies added:
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
cdkVersion: '1.67.0',
|
|
55
|
-
cdkDependencies: ['@aws-cdk/aws-ec2'],
|
|
56
|
-
cdkTestDependencies: ['@aws-cdk/assert'],
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
`cdkDependencies` will add both dependencies and peerDependencies to your package.json file with a caret semver
|
|
60
|
-
requirement (e.g. `^1.67.0`). CDK dependencies must be both direct and peer dependencies,
|
|
61
|
-
see [this issue](https://github.com/aws/aws-cdk/issues/5064). You can set `cdkVersionPinning` to `true` to use a fixed
|
|
62
|
-
version, but this means that any consumer of your library will have to use this exact CDK version.
|
|
63
|
-
Likewise, `cdkTestDependencies` will add dependencies to the `devDependencies`.
|
|
64
|
-
|
|
65
|
-
Additionally, you can add CDK dependencies using the methods:
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
project.addCdkDependencies('aws-cdk/aws-sqs', 'aws-cdk/aws-sns');
|
|
69
|
-
project.addCdkTestDependencies('aws-cdk/something-else');
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
> The `@aws-cdk/assert` library is already added to the `cdkTestDependencies` for you.
|
|
73
|
-
|
|
74
|
-
### Depending on other modules
|
|
75
|
-
|
|
76
|
-
If your library consumes other jsii modules, you should declare them thorugh the `deps` or `peerDeps` options. `deps` should be used if
|
|
77
|
-
types from the consumed module is _not_ part of the public API of the library (the module is used as an implementation detail),
|
|
78
|
-
while `peerDeps` _must_ be used if types from the consumed module are exported as part of your library's API. You can read more
|
|
79
|
-
[here](https://github.com/aws/jsii/blob/master/docs/configuration.md#dependency-considerations).
|
|
80
|
-
|
|
81
|
-
```ts
|
|
82
|
-
deps: [ 'cdk-time-bomb' ]
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
A [dependabot](https://dependabot.com/) file will be added unless `dependabot` is set to 'false'.
|
|
86
|
-
|
|
87
|
-
## Publishing
|
|
88
|
-
|
|
89
|
-
As this is a [jsii project](./jsii.md), it will cross-compile to other languages. You can set up
|
|
90
|
-
any number of jsii target languages.
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
publishToNuget: {
|
|
94
|
-
dotNetNamespace: 'Acme.HelloNamespace',
|
|
95
|
-
packageId: 'Acme.HelloPackage'
|
|
96
|
-
},
|
|
97
|
-
publishToMaven: {
|
|
98
|
-
javaPackage: 'com.acme.hello',
|
|
99
|
-
mavenArtifactId: 'hello-jsii',
|
|
100
|
-
mavenGroupId: 'com.acme.hello'
|
|
101
|
-
serverId: 'github',
|
|
102
|
-
repositoryUrl: 'https://maven.pkg.github.com/example/hello-jsii',
|
|
103
|
-
},
|
|
104
|
-
publishToPypi: {
|
|
105
|
-
distName: 'acme.hello-jsii',
|
|
106
|
-
module: 'acme.hello_jsii'
|
|
107
|
-
},
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
[jsii-release](https://github.com/aws/jsii-release) is used for publishing, and requires uploading [Github project secrets](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets) based on the repositories you wish to publish to:
|
|
111
|
-
|
|
112
|
-
* npm - `NPM_TOKEN` ([docs](https://github.com/aws/jsii-release#npm))
|
|
113
|
-
* .NET - `NUGET_API_KEY` ([docs](https://github.com/aws/jsii-release#nuget))
|
|
114
|
-
* Java: `MAVEN_GPG_PRIVATE_KEY`, `MAVEN_GPG_PRIVATE_KEY_PASSPHRASE`, `MAVEN_PASSWORD`, `MAVEN_USERNAME`, `MAVEN_STAGING_PROFILE_ID` ([docs](https://github.com/aws/jsii-release#maven))
|
|
115
|
-
* Python: `TWINE_USERNAME`, `TWINE_PASSWORD` ([docs](https://github.com/aws/jsii-release#pypi))
|
|
116
|
-
|
|
117
|
-
For help in getting these secrets for your project, read the [jsii-release](https://github.com/aws/jsii-release).
|
|
118
|
-
|
|
119
|
-
If you don't want to publish a particular package, do not include the `dotnet`, `java`, or `python` field.
|
|
120
|
-
|
|
121
|
-
## Workflows
|
|
122
|
-
|
|
123
|
-
Two workflows will be created as Github Actions:
|
|
124
|
-
|
|
125
|
-
* The Build workflow - controlled by the `buildWorkflow` field. On a 'pull_request' or 'workflow_dispatch' the library
|
|
126
|
-
will be built and checked for anti-tamper (ensure no manual changes to generated files).
|
|
127
|
-
* The Release workflow - controlled by the `releaseWorkflow` field. On a push to `main` (overridden at
|
|
128
|
-
`props.defaultReleaseBranch`) the library is built, anti-tampered, version bumped with a commit, pushed back to git,
|
|
129
|
-
and then published to the configured artifact repositories (e.g. npm, pypi).
|
|
130
|
-
|
|
131
|
-
## Tasks
|
|
132
|
-
|
|
133
|
-
There are a number of package scripts that are created for you. Any of them can be overwritten using the `addScript*`
|
|
134
|
-
methods.
|
|
135
|
-
|
|
136
|
-
script|description
|
|
137
|
-
---|---
|
|
138
|
-
start|starts an interactive command menu
|
|
139
|
-
projen|regenerates the projen config. Run this if you edit .projenrc.js
|
|
140
|
-
no-changes|a helper script to prevent unnecessary releases.
|
|
141
|
-
bump|bumps the package version number
|
|
142
|
-
release|bumps the library's version and pushes to origin
|
|
143
|
-
projen:upgrade|upgrades the projen cli tool
|
|
144
|
-
compile|builds the library and generates docs
|
|
145
|
-
watch|compiles and then re-compiles of further changes
|
|
146
|
-
package|runs jsii-pacmak to package your library for publishing
|
|
147
|
-
test|compiles and runs automated tests
|
|
148
|
-
test:watch|watches for file changes, re-compiles and re-tests
|
|
149
|
-
test:update|update any test snapshots
|
|
150
|
-
eslint|runs eslint against all `src` and `test` .ts files
|
|
151
|
-
compat|checks for jsii compatibility. See [here](https://github.com/aws/jsii/tree/master/packages/jsii-diff) for more info.
|
|
152
|
-
docgen|generate documentation
|
|
153
|
-
|
|
154
|
-
As you develop your library you'll likely be using the `test:watch` command the most.
|
|
155
|
-
|
|
156
|
-
## API Documentation
|
|
157
|
-
|
|
158
|
-
Docs will be generated from [Typescript comments](https://typedoc.org/guides/doccomments/) and saved in the `API.md` file.
|
|
159
|
-
Please review this file regularly and document your constructs liberally.
|
|
160
|
-
|
|
161
|
-
## Project structure
|
|
162
|
-
|
|
163
|
-
```
|
|
164
|
-
.
|
|
165
|
-
|--lib/ (build output)
|
|
166
|
-
|--src/
|
|
167
|
-
|--index.ts
|
|
168
|
-
|--test/
|
|
169
|
-
|--hello.test.ts
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
Source .ts files should reside in the `src` directory. Constructs should be exported from the index.ts file.
|
|
173
|
-
Compiled files will be put in the `lib` directory. Tests are in the `test` directory. If you need additional
|
|
174
|
-
resources that are packaged with your library, add those to a `resources` directory that is besides the `src` directory
|
|
175
|
-
and modify your references accordingly:
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
const thing = require('../resources/some-resource.json')
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
## Migrating existing projects
|
|
182
|
-
|
|
183
|
-
Your existing CDK constructs likely have a different file structure than what this projen project expects. Projen projects
|
|
184
|
-
are highly opinionated. There are a few expectations of this project you should modify your existing library to conform to:
|
|
185
|
-
|
|
186
|
-
* All .ts files are expected to be in the `src/` directory. Existing constructs should all be moved there. However,
|
|
187
|
-
you can override this directory by setting `srcdir`.
|
|
188
|
-
* Compiled .js and .d.ts files will go into the `lib/` directory. This directory will be removed and rebuilt each build.
|
|
189
|
-
Do not store source .ts files in your `lib/` or 'libdir'.
|
|
190
|
-
* The entrypoint file for all constructs should be `src/index.ts`. If your existing library is not in the index.ts file,
|
|
191
|
-
you can add the following to export it:
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
export * from './our-s3-bucket'
|
|
195
|
-
```
|
package/docs/awscdk.md
DELETED
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
# AWS Cloud Projects
|
|
2
|
-
|
|
3
|
-
We support two types of projects for cloud development powered by the AWS Cloud
|
|
4
|
-
Development Kit (AWS CDK): **apps** and **libraries**. Apps represent complete
|
|
5
|
-
cloud applications while libraries vend constructs which can be consumed by
|
|
6
|
-
other libraries or by apps. Libraries are published to public or internal
|
|
7
|
-
package managers (npm, PyPI, Maven, NuGet, etc) while apps are deployed into AWS
|
|
8
|
-
environments.
|
|
9
|
-
|
|
10
|
-
This section describes features that are available in both cloud libraries and
|
|
11
|
-
applications. See [AWS CDK Construct Library](./awscdk-construct.md) and [AWS
|
|
12
|
-
CDK Applications](./awscdk-apps.md) for specific details about libraries and
|
|
13
|
-
applications.
|
|
14
|
-
|
|
15
|
-
## AWS Lambda Functions
|
|
16
|
-
|
|
17
|
-
AWS Lambda is a serverless compute platform which executes short running code
|
|
18
|
-
within a managed runtime environment.
|
|
19
|
-
|
|
20
|
-
To define AWS Lambda functions, create a file with a `.lambda.ts` suffix under
|
|
21
|
-
the source tree with AWS Lambda handler code.
|
|
22
|
-
|
|
23
|
-
For example, say we create `src/resize-image.lambda.ts` with the following
|
|
24
|
-
content:
|
|
25
|
-
|
|
26
|
-
```ts
|
|
27
|
-
export async function handler(event: any) {
|
|
28
|
-
console.log('I am resizing the image now!');
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
Now run:
|
|
33
|
-
|
|
34
|
-
```sh
|
|
35
|
-
$ npx projen
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
You'll notice that a new file `src/resize-image-function.ts` has been added to
|
|
39
|
-
your project. This is a generated source file which exports a construct named
|
|
40
|
-
`ResizeImageFunction`. This construct is a subclass of
|
|
41
|
-
`@aws-cdk/aws-lambda.Function`, bound to your specific handler. This means that
|
|
42
|
-
you don't need to specify neither the `code` nor the `runtime` options when you
|
|
43
|
-
add it to your app:
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
import { ResizeImageFunction } from './resize-image-function.ts';
|
|
47
|
-
|
|
48
|
-
const handler = new ResizeImageFunction(this, 'ResizeImageFunction', {
|
|
49
|
-
env: {
|
|
50
|
-
FOO: '1234',
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
// all lambda options are supported...
|
|
54
|
-
});
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Under the hood, we also added a compilation task to your project which creates a
|
|
58
|
-
.zip bundle for each handler. This bundle is created with
|
|
59
|
-
[esbuild](https://github.com/evanw/esbuild) and includes only your handler code
|
|
60
|
-
and all of its dependencies. This means that you can freely install and use any
|
|
61
|
-
dependencies in your project and use them in your handlers. You can manually
|
|
62
|
-
bundle your handler by executing the `bundle:HANDLER` or `bundle:watch:HANDLER`
|
|
63
|
-
tasks.
|
|
64
|
-
|
|
65
|
-
To customize this behavior for all functions, use `lambdaOptions` at the project
|
|
66
|
-
level. For example:
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
const { awscdk } = require('projen');
|
|
70
|
-
|
|
71
|
-
new AwsCdkConstructLibrary({
|
|
72
|
-
// ...
|
|
73
|
-
lambdaOptions: {
|
|
74
|
-
// target node.js runtime
|
|
75
|
-
runtime: awscdk.LambdaRuntime.NODEJS_18_X,
|
|
76
|
-
|
|
77
|
-
bundlingOptions: {
|
|
78
|
-
// list of node modules to exclude from the bundle
|
|
79
|
-
externals: [ 'aws-sdk' ],
|
|
80
|
-
sourcemap: true,
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
You can also disable auto-discovery by setting `lambdaAutoDiscover` to
|
|
87
|
-
`false` and then create explicitly add a `awscdk.LambdaFunction` component for
|
|
88
|
-
each function in your project. This will allow you to perform more
|
|
89
|
-
customizations as needed.
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
const { awscdk } = require('projen');
|
|
93
|
-
|
|
94
|
-
const p = new AwsCdkTypeScriptApp({
|
|
95
|
-
lambdaAutoDiscover: false
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
new awscdk.LambdaFunction(p, {
|
|
99
|
-
entrypoint: 'src/foo.lambda.ts', // .lambda.ts extension is still required
|
|
100
|
-
runtime: aws_lambda.Runtime.NODEJS_12_X,
|
|
101
|
-
});
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## AWS Lambda Extensions
|
|
105
|
-
|
|
106
|
-
An AWS [Lambda Extension][lambda-extensions-blog] is a way to integrate your
|
|
107
|
-
preferred development, monitoring, observability, and governance tools with
|
|
108
|
-
AWS Lambda.
|
|
109
|
-
|
|
110
|
-
Functionally, AWS [Lambda Extensions][lambda-extensions-blog] are long-running
|
|
111
|
-
executable files that reside in the `extensions` subdirectory of your code
|
|
112
|
-
asset. AWS Lambda executes all extensions before starting your handler's main
|
|
113
|
-
process. These AWS Lambda Extensions interact with your function's main process
|
|
114
|
-
and the [Lambda Extension API][lambda-extensions-api] to integrate with tools
|
|
115
|
-
outside the Lambda environment. Projen helps with bundling and preparing your
|
|
116
|
-
code as reusable Lambda Layers.
|
|
117
|
-
|
|
118
|
-
[lambda-extensions-blog]: https://aws.amazon.com/blogs/aws/getting-started-with-using-your-favorite-operational-tools-on-aws-lambda-extensions-are-now-generally-available/
|
|
119
|
-
[lambda-extensions-api]: https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html
|
|
120
|
-
|
|
121
|
-
To create an AWS Lambda Extension with Projen:
|
|
122
|
-
|
|
123
|
-
- Create a file in your project's source tree called
|
|
124
|
-
`my-extension.lambda-extension.ts`
|
|
125
|
-
- Run `npx projen`
|
|
126
|
-
- Projen will automatically discover this file, generating an AWS Lambda Layer
|
|
127
|
-
Version named `MyExtensionLayerVersion` in a file named
|
|
128
|
-
`my-extension-layer-version.ts`.
|
|
129
|
-
- Now you can instantiate `MyExtensionLayerVersion` and add it to your Lambda
|
|
130
|
-
functions.
|
|
131
|
-
|
|
132
|
-
Offical AWS extension examples are available in the [AWS Samples][ext-samples]
|
|
133
|
-
repository.
|
|
134
|
-
|
|
135
|
-
[ext-samples]: https://github.com/aws-samples/aws-lambda-extensions
|
|
136
|
-
|
|
137
|
-
**Example of an extension:**
|
|
138
|
-
|
|
139
|
-
A skeleton for a Lambda extension follows below. Comments with `TODO` describe
|
|
140
|
-
locations where you can provide your custom functionality.
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
#!/usr/bin/env node
|
|
144
|
-
// ^ Don't forget this shebang - Lambda executes the bundled version of this
|
|
145
|
-
// file directly and doesn't otherwise know it's a node script.
|
|
146
|
-
|
|
147
|
-
import { basename } from 'path';
|
|
148
|
-
|
|
149
|
-
// This example uses the `got` HTTP client and assumes that you have included
|
|
150
|
-
// `got` in your `devDependencies`. But, you can use any HTTP client you like.
|
|
151
|
-
import got from 'got';
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Your Lambda Extension's main loop
|
|
155
|
-
*/
|
|
156
|
-
async function main() {
|
|
157
|
-
const extensionInfo = await registerExtension([
|
|
158
|
-
ExtensionEventType.SHUTDOWN,
|
|
159
|
-
ExtensionEventType.INVOKE,
|
|
160
|
-
]);
|
|
161
|
-
|
|
162
|
-
// TODO: Put your initialization code here. You can do things like
|
|
163
|
-
// testing a connection to your external tooling here.
|
|
164
|
-
|
|
165
|
-
while (true) {
|
|
166
|
-
const event = await getNextEvent(extensionInfo.extensionId);
|
|
167
|
-
|
|
168
|
-
switch (event.eventType) {
|
|
169
|
-
case ExtensionEventType.SHUTDOWN:
|
|
170
|
-
// TODO: Do something when the lambda extension is being
|
|
171
|
-
// shut down. You might do things here like de-registering
|
|
172
|
-
// your extension from your external tooling.
|
|
173
|
-
return 0;
|
|
174
|
-
|
|
175
|
-
case ExtensionEventType.INVOKE:
|
|
176
|
-
// TODO: Do something every time your function is invoked,
|
|
177
|
-
// such as re-establishing a connection with your external
|
|
178
|
-
// tooling after the Lambda has thawed from a period of
|
|
179
|
-
// freezing due to inactivity.
|
|
180
|
-
break;
|
|
181
|
-
|
|
182
|
-
default:
|
|
183
|
-
console.log(`Unhandled event type ${event.eventType}`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const EXTENSION_API_BASE_URL = `http://${process.env.AWS_LAMBDA_RUNTIME_API}/2020-01-01/extension`;
|
|
189
|
-
|
|
190
|
-
enum ExtensionEventType {
|
|
191
|
-
INVOKE = 'INVOKE',
|
|
192
|
-
SHUTDOWN = 'SHUTDOWN',
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
interface ExtensionEvent {
|
|
196
|
-
readonly eventType: ExtensionEventType;
|
|
197
|
-
// For complete event structures, see:
|
|
198
|
-
// https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
async function registerExtension(events: ExtensionEventType[]) {
|
|
202
|
-
// Do not set a timeout on the GET call, as the extension can be suspended
|
|
203
|
-
// for a period of time until there is an event to return.
|
|
204
|
-
const res = await got.post(`${EXTENSION_API_BASE_URL}/register`, {
|
|
205
|
-
json: { events },
|
|
206
|
-
headers: {
|
|
207
|
-
'Lambda-Extension-Name': basename(__filename),
|
|
208
|
-
},
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
const header = res.headers['lambda-extension-identifier'];
|
|
212
|
-
const extensionId = Array.isArray(header) ? header[0] : header;
|
|
213
|
-
const json = JSON.parse(res.body);
|
|
214
|
-
|
|
215
|
-
return {
|
|
216
|
-
extensionId,
|
|
217
|
-
functionName: json.functionName as string,
|
|
218
|
-
functionVersion: json.functionVersion as string,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function getNextEvent(extensionId: string): Promise<ExtensionEvent> {
|
|
223
|
-
return got(`${EXTENSION_API_BASE_URL}/event/next`, {
|
|
224
|
-
headers: {
|
|
225
|
-
'Lambda-Extension-Identifier': extensionId,
|
|
226
|
-
},
|
|
227
|
-
}).json();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
main()
|
|
231
|
-
.then(statusCode => {
|
|
232
|
-
process.exit(statusCode);
|
|
233
|
-
})
|
|
234
|
-
.catch(e => {
|
|
235
|
-
console.error(e);
|
|
236
|
-
process.exit(1);
|
|
237
|
-
});
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
## Integration Snapshot Tests
|
|
241
|
-
|
|
242
|
-
Files in the `test/` tree with the `.integ.ts` suffix are recognized as
|
|
243
|
-
*integration snapshot tests*.
|
|
244
|
-
|
|
245
|
-
Each test is a simple CDK app (e.g. calls `app.synth()`) which exercises certain
|
|
246
|
-
construct(s) within the project. A test is considered passing if the app can be
|
|
247
|
-
successfully deployed.
|
|
248
|
-
|
|
249
|
-
To create/update the snapshot, developers are expected to execute the task
|
|
250
|
-
`integ:NAME:deploy` with AWS credentials for their personal development
|
|
251
|
-
environment. This task will deploy the test app to their account. Upon
|
|
252
|
-
successful deployment (i.e. the test passed), the snapshot will be captured and
|
|
253
|
-
stored under a directory called `xxx.integ.snapshot` next to the test
|
|
254
|
-
entrypoint. This directory should be committed to the repository.
|
|
255
|
-
|
|
256
|
-
During builds (either local or within a workflow), the task `integ:NAME:assert`
|
|
257
|
-
will be executed. This task synthesizes the test app and compares the output to
|
|
258
|
-
the captured snapshot. The build will fail if the output differs.
|
|
259
|
-
|
|
260
|
-
For each integration test, the following set of tasks are created:
|
|
261
|
-
|
|
262
|
-
| Task | Description |
|
|
263
|
-
| --------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
264
|
-
| `integ:NAME:deploy` | Deploys & destroys the test app and updates the snapshot. |
|
|
265
|
-
| `integ:NAME:assert` | Synthesizes the test app and compares it with the snapshot (this is the task that runs during build) |
|
|
266
|
-
| `integ:NAME:snapshot` | Synthesizes the test app and updates the snapshot (not recommended to use because it bypasses deployment). |
|
|
267
|
-
| `integ:NAME:destroy` | Destroys a previously deployed test app. |
|
|
268
|
-
|
|
269
|
-
### Writing test assertions
|
|
270
|
-
|
|
271
|
-
You can write your test assertions as AWS Lambda handlers and use the AWS CDK
|
|
272
|
-
[triggers][cdk-trigger-docs] module to execute them as part of the deployment.
|
|
273
|
-
|
|
274
|
-
Here is an example of a test:
|
|
275
|
-
|
|
276
|
-
```ts
|
|
277
|
-
import { App,Stack } from '@aws-cdk/core';
|
|
278
|
-
import { Trigger } from '@aws-cdk/triggers';
|
|
279
|
-
import { ConstructUnderTest } from '../src';
|
|
280
|
-
import { AssertSomeStuffFunction } from './assert-some-stuff-function.ts'; // <-- generated
|
|
281
|
-
|
|
282
|
-
const app = new App();
|
|
283
|
-
const stack = new Stack(app, 'Test');
|
|
284
|
-
|
|
285
|
-
// this is the construct we want to test
|
|
286
|
-
const testee = new ConstructUnderTest(stack, 'ConstructUnderTest');
|
|
287
|
-
|
|
288
|
-
// execute a lambda handler with some assertions after all testee
|
|
289
|
-
// resources are created
|
|
290
|
-
new Trigger(stack, 'RunAssertions', {
|
|
291
|
-
executeAfter: [testee],
|
|
292
|
-
handler: new AssertSomeStuffFunction(stack, 'AssertSomeStuffFunction', {
|
|
293
|
-
env: {
|
|
294
|
-
URL: testee.url // <-- some reference to the created construct
|
|
295
|
-
}
|
|
296
|
-
}),
|
|
297
|
-
});
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
[cdk-trigger-docs]:https://docs.aws.amazon.com/cdk/api/v1/docs/triggers-readme.html
|
|
301
|
-
|
|
302
|
-
## Experimental `integ-runner` integration tests
|
|
303
|
-
|
|
304
|
-
For TypeScript-based AWS CDK projects, Projen provides experimental support
|
|
305
|
-
for using the [`integ-runner`][integ-runner] tool and [library][integ-library]
|
|
306
|
-
for integration testing. To enable this feature, you specify
|
|
307
|
-
`experimentalIntegRunner: true` in your project options.
|
|
308
|
-
|
|
309
|
-
[integ-runner]: https://github.com/aws/aws-cdk/tree/main/packages/%40aws-cdk/integ-runner
|
|
310
|
-
[integ-library]: https://docs.aws.amazon.com/cdk/api/v2/docs/integ-tests-alpha-readme.html
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
```typescript
|
|
314
|
-
import { awscdk } from 'projen';
|
|
315
|
-
|
|
316
|
-
new awscdk.AwsCdkConstructLibrary({
|
|
317
|
-
// ...
|
|
318
|
-
experimentalIntegRunner: true
|
|
319
|
-
});
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
After enabling experimental `integ-runner` support, all `integ.*.ts` files in
|
|
323
|
-
the `test` directory will be automatically discovered and treated as
|
|
324
|
-
integration tests. Projen will check that these integration tests match the
|
|
325
|
-
committed snapshots at build-time, or whenever the test task is run.
|
|
326
|
-
|
|
327
|
-
Projen also provides two new commands:
|
|
328
|
-
|
|
329
|
-
`projen integ [...test names]` - Verifies integration test snapshots. If test
|
|
330
|
-
names are provided, only the provided integration tests will be checked.
|
|
331
|
-
Otherwise, all integration tests will be checked.
|
|
332
|
-
|
|
333
|
-
`projen integ:update [...test names]` - Verifies integration test snapshots or
|
|
334
|
-
updates the integration test snapshot by re-running the integration test on
|
|
335
|
-
failure. Like `projen integ`, you may specify zero or more test names.
|
|
336
|
-
|
|
337
|
-
> Tests are named based on their file path. For instance, with an integration
|
|
338
|
-
> test contained in `test/r53writer/integ.ddbStreamHandler.ts`, the test name
|
|
339
|
-
> is `r53writer/integ.ddbStreamHandler`, and you could update the test's
|
|
340
|
-
> snapshot by running `projen integ:update r53writer/integ.ddbStreamHandler`.
|
|
341
|
-
|
|
342
|
-
## Watch
|
|
343
|
-
|
|
344
|
-
> Only relevant for app projects
|
|
345
|
-
|
|
346
|
-
The `watch` command will use [cdk watch] in order to trigger deployments (with
|
|
347
|
-
opportunistic hot-swapping) when source files or asset bundles are updated.
|
|
348
|
-
`cdk.json` will automatically be configured to watch both source code changes
|
|
349
|
-
and bundles, and rebuild bundles as needed.
|
|
350
|
-
|
|
351
|
-
[cdk watch]: https://aws.amazon.com/blogs/developer/increasing-development-speed-with-cdk-watch/
|
|
352
|
-
|
|
353
|
-
To start watching, set up your environment with AWS credentials and `AWS_REGION`
|
|
354
|
-
pointing to your development AWS account and execute:
|
|
355
|
-
|
|
356
|
-
```sh
|
|
357
|
-
npx projen watch
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
This will:
|
|
361
|
-
|
|
362
|
-
* Bundle your assets (if you have any).
|
|
363
|
-
* Perform an initial deployment of your app into your development environment.
|
|
364
|
-
* Start watching for changes.
|
|
365
|
-
|
|
366
|
-
If you change a source file in your project, this change will be picked up by
|
|
367
|
-
`cdk watch`, assets will be re-bundled and a hotswap deployment will be
|
|
368
|
-
performed. For example, if you only change some AWS Lambda code, the CDK CLI
|
|
369
|
-
will simply update the AWS Lambda service with the location of your new code
|
|
370
|
-
bundle instead of going through an AWS CloudFormation deployment.
|
|
371
|
-
|
|
372
|
-
## Roadmap
|
|
373
|
-
|
|
374
|
-
* Additional bundling targets: web apps, ECS
|
|
375
|
-
* Local execution for AWS Lambda, ECS containers, Step Functions
|
|
376
|
-
* Support different provisioning engines (CloudFormation/Terraform) using Terraform L2 support
|
|
377
|
-
* Generate types for strong-typing AWS Lambda/ECS environment bindings.
|
package/docs/build.md
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# Build
|
|
2
|
-
|
|
3
|
-
Projen defines a standard way for building software through a fixed set of
|
|
4
|
-
*build phases*. This is implemented via a set of [tasks](./tasks.md) defined in
|
|
5
|
-
the `Project` base class.
|
|
6
|
-
|
|
7
|
-
The `build` task spawns a set of sub-tasks which represent the various build phases:
|
|
8
|
-
|
|
9
|
-
* `default` - this task is responsible to execute your projenrc and synthesize all project files.
|
|
10
|
-
* `pre-compile` - runs before compilation (eg. bundle assets)
|
|
11
|
-
* `compile` - compile your code (if needed)
|
|
12
|
-
* `post-compile` - runs immediately after a successful compilation
|
|
13
|
-
* `test` - runs tests
|
|
14
|
-
* `package` - creates a distribution package
|
|
15
|
-
|
|
16
|
-
To extend the build process, components and projects can use
|
|
17
|
-
`project.projectBuild.xxxTask` and interact with the `Task` object (i.e.
|
|
18
|
-
`project.projectBuild.postCompileTask.exec("echo hi")` will execute `echo hi` after
|
|
19
|
-
compilation).
|
|
20
|
-
|
|
21
|
-
> NOTE: the `build` task is locked. This means that any attempt to extend it
|
|
22
|
-
> (i.e. call `spawn`, `exec`, `reset`, etc) will throw an exception. Instead of
|
|
23
|
-
> extending `build`, just extend one of the phases. This ensures that phases are
|
|
24
|
-
> always executed in the right order.
|
|
25
|
-
|
|
26
|
-
## Build Workflow
|
|
27
|
-
|
|
28
|
-
The `build` workflow is responsible to build your project when a pull request is
|
|
29
|
-
submitted against it.
|
|
30
|
-
|
|
31
|
-
### Self-mutation
|
|
32
|
-
|
|
33
|
-
Projen synthesizes files that are part of your source repository. This means
|
|
34
|
-
that when you change you projenrc file, and execute `projen`, other files in
|
|
35
|
-
your repo may change as a result.
|
|
36
|
-
|
|
37
|
-
This is also relevant in other situations where your build process _mutates_
|
|
38
|
-
your repository. For example, if you use **snapshot testing**, your repository
|
|
39
|
-
includes snapshots which represent expected test results. When your code
|
|
40
|
-
changes, you will likely need to update those snapshots as well.
|
|
41
|
-
|
|
42
|
-
To ensure that a pull request branch always represent the final state of the
|
|
43
|
-
repository, you can enable the `mutableBuild` option in your project
|
|
44
|
-
configuration (currently only supported for projects derived from
|
|
45
|
-
`NodeProject`).
|
|
46
|
-
|
|
47
|
-
When enabled, the PR build workflow (also called `build`) will push any modified
|
|
48
|
-
files to the PR branch after a successful build, so that the branch will always
|
|
49
|
-
reflect the most up-to-date version of all generated files.
|
|
50
|
-
|
|
51
|
-
> This feature does not work for forks since it is impossible to safely push
|
|
52
|
-
> changes to a fork from a PR build. If a PR is created from a fork of the
|
|
53
|
-
> repository and there are build mutations, the PR build will fail (indicating
|
|
54
|
-
> that it cannot push to the fork). To fix this, the branch needs to be updated
|
|
55
|
-
> (same behavior as if mutable builds was disabled).
|
package/docs/bundling.md
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Bundling
|
|
2
|
-
|
|
3
|
-
The `Bundler` component (for Node.js projects) can be used to produce JavaScript
|
|
4
|
-
bundles from source files.
|
|
5
|
-
|
|
6
|
-
It is included by default in all projects derived from `NodeProject`.
|
|
7
|
-
|
|
8
|
-
To customize, use `bundlerOptions`:
|
|
9
|
-
|
|
10
|
-
```ts
|
|
11
|
-
const project = new NodeProject({
|
|
12
|
-
esbuildVersion: '^0.13.13', // default to "latest"
|
|
13
|
-
assetsDir: 'resources', // defaults to "assets"
|
|
14
|
-
});
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
To add bundles, call `bundler.addBundle()`:
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
project.bundler.addBundle('name-of-bundle', {
|
|
21
|
-
entrypoint: 'src/foo.ts',
|
|
22
|
-
target: 'node18',
|
|
23
|
-
platform: 'node',
|
|
24
|
-
bundlingOptions: {
|
|
25
|
-
externals: ['aws-sdk'], // modules not to include in bundles
|
|
26
|
-
sourcemap: true, // default is false
|
|
27
|
-
watchTask: false, // should we create a "bundle:watch" task for each bundle
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
```
|