@ashishpandeyone/cdk-lambda-web-function 0.1.3 → 0.1.4
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 +759 -264
- package/.jsii.tabl.json +1 -1
- package/API.md +1006 -237
- package/README.md +23 -3
- package/assets/web-function-provider/index.js +23 -23
- package/lib/nodejs-web-function.js +1 -1
- package/lib/private/code-bucket.d.ts +3 -0
- package/lib/private/code-bucket.js +18 -2
- package/lib/private/provider-protocol.d.ts +13 -0
- package/lib/private/provider-protocol.js +9 -2
- package/lib/private/provider.d.ts +3 -2
- package/lib/private/provider.js +25 -4
- package/lib/web-function-deployment.js +1 -1
- package/lib/web-function-endpoint.js +1 -1
- package/lib/web-function-grants.d.ts +7 -1
- package/lib/web-function-grants.js +15 -7
- package/lib/web-function-revision.js +1 -1
- package/lib/web-function.d.ts +104 -34
- package/lib/web-function.js +124 -57
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -156,6 +156,25 @@ const signed = await signer.sign(
|
|
|
156
156
|
const response = await fetch(`https://${host}/`, { headers: signed.headers });
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
+
### Functions defined elsewhere
|
|
160
|
+
|
|
161
|
+
Import a Web Function defined in another stack or app to grant access to it, read its metrics, or reference its revisions:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
const orders = WebFunction.fromWebFunctionArn(this, 'Orders', 'arn:aws:lambda:us-east-1:111122223333:web-function/orders');
|
|
165
|
+
orders.grantInvoke(consumerRole); // every endpoint of the function
|
|
166
|
+
|
|
167
|
+
const live = WebFunction.fromWebFunctionAttributes(this, 'Live', {
|
|
168
|
+
webFunctionName: 'orders', // in this stack's account and region
|
|
169
|
+
endpointName: 'live', // grantInvoke allows this endpoint only
|
|
170
|
+
});
|
|
171
|
+
live.metricConcurrentRequests().createAlarm(this, 'Busy', { threshold: 60, evaluationPeriods: 3 });
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
An imported function's metrics default to its own region. Its endpoints, revisions and log groups stay with the stack that defines it.
|
|
175
|
+
|
|
176
|
+
`grantInvoke` adds to the caller's IAM policy, which is all a caller in the function's account needs. A caller in another account also needs the function's resource policy to allow it, which this library doesn't manage yet.
|
|
177
|
+
|
|
159
178
|
## Configuration
|
|
160
179
|
|
|
161
180
|
```ts
|
|
@@ -207,7 +226,9 @@ new NodejsWebFunction(this, 'Api', {
|
|
|
207
226
|
|
|
208
227
|
`code` takes any `lambda.Code` that produces a zip in S3: `fromAsset`, `fromBucket`/`fromBucketV2`, `fromCustomCommand`, `fromDockerBuild`. Inline code and container images fail at synth time.
|
|
209
228
|
|
|
210
|
-
Lambda Web Functions download code as the `lambda.amazonaws.com` service principal, from a **versioned** bucket, and the CDK bootstrap bucket allows neither. So each stack gets a small code bucket, and the code is copied into it on deploy.
|
|
229
|
+
Lambda Web Functions download code as the `lambda.amazonaws.com` service principal, from a **versioned** bucket, and the CDK bootstrap bucket allows neither. So each stack gets a small code bucket, and the code is copied into it on deploy. The bucket is emptied and deleted with the stack.
|
|
230
|
+
|
|
231
|
+
Code copies, log groups in other regions, revision cleanup and the bucket's emptying run in one custom resource Lambda per stack. Its logs go to a log group the stack owns, kept for a month and deleted with the stack.
|
|
211
232
|
|
|
212
233
|
## Revisions
|
|
213
234
|
|
|
@@ -364,10 +385,9 @@ new WebFunction(this, 'Api', {
|
|
|
364
385
|
|
|
365
386
|
## Limitations
|
|
366
387
|
|
|
367
|
-
- Not yet supported:
|
|
388
|
+
- Not yet supported: VPC access (network connectors), resource-policy permissions, KMS encryption, tracing, and a CloudFront origin.
|
|
368
389
|
- `cdk deploy --hotswap` and `cdk watch` don't support Web Functions.
|
|
369
390
|
- Quotas: 10 endpoints and about 50 revisions per function (Lambda cleans up older revisions automatically), and 10,000 requests per second per endpoint. Per account and region: 100,000 requests per second and 2,000 Arm64 vCPUs (each execution environment uses 2). The account quotas are adjustable, and new accounts start lower. See [Lambda quotas](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html).
|
|
370
|
-
- The stack's custom resource provider Lambda keeps its own log group after the stack is deleted, as with other CDK custom resources.
|
|
371
391
|
|
|
372
392
|
## Development
|
|
373
393
|
|