sst 2.0.0-rc.65 → 2.0.0-rc.67
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/cli/commands/deploy.js +1 -1
- package/cli/commands/dev.js +1 -1
- package/cli/ui/deploy.js +1 -1
- package/constructs/ApiGatewayV1Api.d.ts +1 -2
- package/constructs/Auth.js +1 -0
- package/constructs/NextjsSite.js +1 -2
- package/constructs/SsrSite.d.ts +6 -11
- package/constructs/SsrSite.js +2 -4
- package/constructs/index.d.ts +0 -3
- package/constructs/index.js +0 -3
- package/node/api/index.d.ts +0 -3
- package/node/api/index.js +0 -2
- package/package.json +1 -1
- package/sst.mjs +4 -3
- package/constructs/DebugApp.d.ts +0 -49
- package/constructs/DebugApp.js +0 -63
- package/constructs/DebugStack.d.ts +0 -34
- package/constructs/DebugStack.js +0 -132
package/cli/commands/deploy.js
CHANGED
|
@@ -63,7 +63,7 @@ export const deploy = (program) => program.command("deploy [filter]", "Deploy yo
|
|
|
63
63
|
process.exit(1);
|
|
64
64
|
}
|
|
65
65
|
const component = render(React.createElement(DeploymentUI, { assembly: assembly }));
|
|
66
|
-
const results = await Stacks.deployMany(
|
|
66
|
+
const results = await Stacks.deployMany(target);
|
|
67
67
|
component.clear();
|
|
68
68
|
component.unmount();
|
|
69
69
|
printDeploymentResults(assembly, results);
|
package/cli/commands/dev.js
CHANGED
|
@@ -74,7 +74,7 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
|
|
|
74
74
|
});
|
|
75
75
|
bus.subscribe("function.build.failed", async (evt) => {
|
|
76
76
|
const info = useFunctions().fromID(evt.properties.functionID);
|
|
77
|
-
if (
|
|
77
|
+
if (info.enableLiveDev === false)
|
|
78
78
|
return;
|
|
79
79
|
Colors.gap();
|
|
80
80
|
Colors.line(Colors.danger("✖ "), "Build failed", info.handler);
|
package/cli/ui/deploy.js
CHANGED
|
@@ -23,7 +23,7 @@ export const DeploymentUI = (props) => {
|
|
|
23
23
|
? Colors.dim(`${stackNameToId(event.StackName)} ${readable} ${event.ResourceType}`)
|
|
24
24
|
: Colors.dim(`${stackNameToId(event.StackName)} ${event.ResourceType}`), Stacks.isFailed(event.ResourceStatus)
|
|
25
25
|
? Colors.danger(event.ResourceStatus)
|
|
26
|
-
: Colors.dim(event.ResourceStatus));
|
|
26
|
+
: Colors.dim(event.ResourceStatus), Stacks.isFailed(event.ResourceStatus) && event.ResourceStatusReason);
|
|
27
27
|
const { [event.LogicalResourceId]: _, ...next } = previous;
|
|
28
28
|
return next;
|
|
29
29
|
}
|
|
@@ -9,7 +9,6 @@ import * as apigV1AccessLog from "./util/apiGatewayV1AccessLog.js";
|
|
|
9
9
|
import { Bucket } from "./Bucket.js";
|
|
10
10
|
import { Duration } from "./util/duration.js";
|
|
11
11
|
import { SSTConstruct } from "./Construct.js";
|
|
12
|
-
import { DnsValidatedCertificate } from "./cdk/dns-validated-certificate.js";
|
|
13
12
|
import { Function as Fn, FunctionProps, FunctionInlineDefinition, FunctionDefinition } from "./Function.js";
|
|
14
13
|
import { Permissions } from "./util/permission.js";
|
|
15
14
|
export interface ApiGatewayV1ApiAccessLogProps extends apigV1AccessLog.AccessLogProps {
|
|
@@ -492,7 +491,7 @@ export declare class ApiGatewayV1Api<Authorizers extends Record<string, ApiGatew
|
|
|
492
491
|
/**
|
|
493
492
|
* The internally created certificate
|
|
494
493
|
*/
|
|
495
|
-
certificate?: acm.
|
|
494
|
+
certificate?: acm.ICertificate;
|
|
496
495
|
};
|
|
497
496
|
private _deployment?;
|
|
498
497
|
private _customDomainUrl?;
|
package/constructs/Auth.js
CHANGED
package/constructs/NextjsSite.js
CHANGED
|
@@ -112,8 +112,7 @@ export class NextjsSite extends SsrSite {
|
|
|
112
112
|
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
|
|
113
113
|
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
114
114
|
compress: true,
|
|
115
|
-
cachePolicy: cdk?.
|
|
116
|
-
this.createCloudFrontServerCachePolicy(),
|
|
115
|
+
cachePolicy: cdk?.serverCachePolicy ?? this.createCloudFrontServerCachePolicy(),
|
|
117
116
|
edgeLambdas: isMiddlewareEnabled
|
|
118
117
|
? [
|
|
119
118
|
{
|
package/constructs/SsrSite.d.ts
CHANGED
|
@@ -147,18 +147,13 @@ export interface SsrSiteProps {
|
|
|
147
147
|
*/
|
|
148
148
|
distribution?: SsrCdkDistributionProps;
|
|
149
149
|
/**
|
|
150
|
-
* Override the
|
|
150
|
+
* Override the CloudFront cache policy properties for responses from the
|
|
151
|
+
* server rendering Lambda.
|
|
152
|
+
*
|
|
153
|
+
* @note The default cache policy that is used in the abscene of this property
|
|
154
|
+
* is one that performs no caching of the server response.
|
|
151
155
|
*/
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Override the CloudFront cache policy properties for responses from the
|
|
155
|
-
* server rendering Lambda.
|
|
156
|
-
*
|
|
157
|
-
* @note The default cache policy that is used in the abscene of this property
|
|
158
|
-
* is one that performs no caching of the server response.
|
|
159
|
-
*/
|
|
160
|
-
serverRequests?: ICachePolicy;
|
|
161
|
-
};
|
|
156
|
+
serverCachePolicy?: ICachePolicy;
|
|
162
157
|
server?: Pick<FunctionProps, "vpc" | "vpcSubnets" | "securityGroups" | "allowAllOutbound" | "allowPublicSubnet" | "architecture">;
|
|
163
158
|
};
|
|
164
159
|
}
|
package/constructs/SsrSite.js
CHANGED
|
@@ -483,8 +483,7 @@ export class SsrSite extends Construct {
|
|
|
483
483
|
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
484
484
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
485
485
|
compress: true,
|
|
486
|
-
cachePolicy: cdk?.
|
|
487
|
-
this.createCloudFrontServerCachePolicy(),
|
|
486
|
+
cachePolicy: cdk?.serverCachePolicy ?? this.createCloudFrontServerCachePolicy(),
|
|
488
487
|
...(cfDistributionProps.defaultBehavior || {}),
|
|
489
488
|
};
|
|
490
489
|
}
|
|
@@ -497,8 +496,7 @@ export class SsrSite extends Construct {
|
|
|
497
496
|
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
498
497
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
499
498
|
compress: true,
|
|
500
|
-
cachePolicy: cdk?.
|
|
501
|
-
this.createCloudFrontServerCachePolicy(),
|
|
499
|
+
cachePolicy: cdk?.serverCachePolicy ?? this.createCloudFrontServerCachePolicy(),
|
|
502
500
|
...(cfDistributionProps.defaultBehavior || {}),
|
|
503
501
|
// concatenate edgeLambdas
|
|
504
502
|
edgeLambdas: [
|
package/constructs/index.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ export * from "./Script.js";
|
|
|
15
15
|
export * from "./EventBus.js";
|
|
16
16
|
export * from "./Function.js";
|
|
17
17
|
export * from "./AppSyncApi.js";
|
|
18
|
-
export * from "./DebugStack.js";
|
|
19
18
|
export * from "./WebSocketApi.js";
|
|
20
19
|
export * from "./KinesisStream.js";
|
|
21
20
|
export * from "./ApiGatewayV1Api.js";
|
|
@@ -28,6 +27,4 @@ export * from "./util/duration.js";
|
|
|
28
27
|
export * from "./util/permission.js";
|
|
29
28
|
export * as Config from "./Config.js";
|
|
30
29
|
export * as Metadata from "./Metadata.js";
|
|
31
|
-
export * from "./DebugApp.js";
|
|
32
|
-
export * from "./DebugStack.js";
|
|
33
30
|
export { use, dependsOn, getStack, StackContext } from "./FunctionalStack.js";
|
package/constructs/index.js
CHANGED
|
@@ -15,7 +15,6 @@ export * from "./Script.js";
|
|
|
15
15
|
export * from "./EventBus.js";
|
|
16
16
|
export * from "./Function.js";
|
|
17
17
|
export * from "./AppSyncApi.js";
|
|
18
|
-
export * from "./DebugStack.js";
|
|
19
18
|
export * from "./WebSocketApi.js";
|
|
20
19
|
export * from "./KinesisStream.js";
|
|
21
20
|
export * from "./ApiGatewayV1Api.js";
|
|
@@ -28,6 +27,4 @@ export * from "./util/duration.js";
|
|
|
28
27
|
export * from "./util/permission.js";
|
|
29
28
|
export * as Config from "./Config.js";
|
|
30
29
|
export * as Metadata from "./Metadata.js";
|
|
31
|
-
export * from "./DebugApp.js";
|
|
32
|
-
export * from "./DebugStack.js";
|
|
33
30
|
export { use, dependsOn, getStack } from "./FunctionalStack.js";
|
package/node/api/index.d.ts
CHANGED
|
@@ -10,13 +10,10 @@ export interface ApiGatewayV1ApiResources {
|
|
|
10
10
|
}
|
|
11
11
|
export interface WebSocketApiResources {
|
|
12
12
|
}
|
|
13
|
-
export interface GraphQLApiResources {
|
|
14
|
-
}
|
|
15
13
|
export declare const Api: ApiResources;
|
|
16
14
|
export declare const AppSyncApi: AppSyncApiResources;
|
|
17
15
|
export declare const ApiGatewayV1Api: ApiGatewayV1ApiResources;
|
|
18
16
|
export declare const WebSocketApi: WebSocketApiResources;
|
|
19
|
-
export declare const GraphQLApi: GraphQLApiResources;
|
|
20
17
|
/**
|
|
21
18
|
* Create a new api handler that can be used to create an authenticated session.
|
|
22
19
|
*
|
package/node/api/index.js
CHANGED
|
@@ -5,12 +5,10 @@ export const Api = createProxy("Api");
|
|
|
5
5
|
export const AppSyncApi = createProxy("AppSyncApi");
|
|
6
6
|
export const ApiGatewayV1Api = createProxy("ApiGatewayV1Api");
|
|
7
7
|
export const WebSocketApi = createProxy("WebSocketApi");
|
|
8
|
-
export const GraphQLApi = createProxy("GraphQLApi");
|
|
9
8
|
Object.assign(Api, parseEnvironment("Api", ["url"]));
|
|
10
9
|
Object.assign(AppSyncApi, parseEnvironment("AppSyncApi", ["url"]));
|
|
11
10
|
Object.assign(ApiGatewayV1Api, parseEnvironment("ApiGatewayV1Api", ["url"]));
|
|
12
11
|
Object.assign(WebSocketApi, parseEnvironment("WebSocketApi", ["url"]));
|
|
13
|
-
Object.assign(GraphQLApi, parseEnvironment("GraphQLApi", ["url"]));
|
|
14
12
|
/**
|
|
15
13
|
* Create a new api handler that can be used to create an authenticated session.
|
|
16
14
|
*
|
package/package.json
CHANGED
package/sst.mjs
CHANGED
|
@@ -5443,7 +5443,8 @@ var init_deploy2 = __esm({
|
|
|
5443
5443
|
) : Colors.dim(
|
|
5444
5444
|
`${stackNameToId(event2.StackName)} ${event2.ResourceType}`
|
|
5445
5445
|
),
|
|
5446
|
-
stacks_exports.isFailed(event2.ResourceStatus) ? Colors.danger(event2.ResourceStatus) : Colors.dim(event2.ResourceStatus)
|
|
5446
|
+
stacks_exports.isFailed(event2.ResourceStatus) ? Colors.danger(event2.ResourceStatus) : Colors.dim(event2.ResourceStatus),
|
|
5447
|
+
stacks_exports.isFailed(event2.ResourceStatus) && event2.ResourceStatusReason
|
|
5447
5448
|
);
|
|
5448
5449
|
const { [event2.LogicalResourceId]: _, ...next } = previous2;
|
|
5449
5450
|
return next;
|
|
@@ -6272,7 +6273,7 @@ var dev = (program2) => program2.command(
|
|
|
6272
6273
|
});
|
|
6273
6274
|
bus.subscribe("function.build.failed", async (evt) => {
|
|
6274
6275
|
const info = useFunctions3().fromID(evt.properties.functionID);
|
|
6275
|
-
if (
|
|
6276
|
+
if (info.enableLiveDev === false)
|
|
6276
6277
|
return;
|
|
6277
6278
|
Colors.gap();
|
|
6278
6279
|
Colors.line(Colors.danger("\u2716 "), "Build failed", info.handler);
|
|
@@ -6611,7 +6612,7 @@ var deploy2 = (program2) => program2.command(
|
|
|
6611
6612
|
process.exit(1);
|
|
6612
6613
|
}
|
|
6613
6614
|
const component = render(/* @__PURE__ */ React2.createElement(DeploymentUI2, { assembly }));
|
|
6614
|
-
const results = await Stacks.deployMany(
|
|
6615
|
+
const results = await Stacks.deployMany(target);
|
|
6615
6616
|
component.clear();
|
|
6616
6617
|
component.unmount();
|
|
6617
6618
|
printDeploymentResults2(assembly, results);
|
package/constructs/DebugApp.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { App, StageSynthesisOptions } from "aws-cdk-lib";
|
|
2
|
-
import { CloudAssembly } from "aws-cdk-lib/cx-api";
|
|
3
|
-
/**
|
|
4
|
-
* Deploy props for apps.
|
|
5
|
-
*/
|
|
6
|
-
export interface DebugAppDeployProps {
|
|
7
|
-
/**
|
|
8
|
-
* The app name, used to prefix stacks.
|
|
9
|
-
*/
|
|
10
|
-
name: string;
|
|
11
|
-
/**
|
|
12
|
-
* The stage to deploy this app to.
|
|
13
|
-
*/
|
|
14
|
-
stage: string;
|
|
15
|
-
/**
|
|
16
|
-
* The region to deploy this app to.
|
|
17
|
-
*/
|
|
18
|
-
region: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* The DebugApp construct is used internally by SST to create the resources needed to power Live Lambda Development.
|
|
22
|
-
*/
|
|
23
|
-
export declare class DebugApp extends App {
|
|
24
|
-
/**
|
|
25
|
-
* The name of the app. This comes from the `name` in your `sst.json`.
|
|
26
|
-
*/
|
|
27
|
-
readonly name: string;
|
|
28
|
-
/**
|
|
29
|
-
* The stage the app is being deployed to. If this is not specified as the [`--stage`](/packages/sst.md#--stage) option, it'll default to the stage configured during the initial run of the SST CLI.
|
|
30
|
-
*/
|
|
31
|
-
readonly stage: string;
|
|
32
|
-
/**
|
|
33
|
-
* The region the app is being deployed to. If this is not specified as the [`--region`](/packages/sst.md#--region) option in the SST CLI, it'll default to the `region` in your `sst.json`.
|
|
34
|
-
*/
|
|
35
|
-
readonly region: string;
|
|
36
|
-
/**
|
|
37
|
-
* The AWS account the app is being deployed to. This comes from the IAM credentials being used to run the SST CLI.
|
|
38
|
-
*/
|
|
39
|
-
readonly account: string;
|
|
40
|
-
/**
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
constructor(deployProps: DebugAppDeployProps);
|
|
44
|
-
synth(options?: StageSynthesisOptions): CloudAssembly;
|
|
45
|
-
/**
|
|
46
|
-
* Use this method to prefix resource names in your stacks to make sure they don't thrash when deployed to different stages in the same AWS account. This method will prefix a given resource name with the stage and app name. Using the format `${stage}-${name}-${logicalName}`.
|
|
47
|
-
*/
|
|
48
|
-
logicalPrefixedName(logicalName: string): string;
|
|
49
|
-
}
|
package/constructs/DebugApp.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { App } from "aws-cdk-lib";
|
|
2
|
-
import { isStackConstruct, isSSTDebugStack } from "./Construct.js";
|
|
3
|
-
/**
|
|
4
|
-
* The DebugApp construct is used internally by SST to create the resources needed to power Live Lambda Development.
|
|
5
|
-
*/
|
|
6
|
-
export class DebugApp extends App {
|
|
7
|
-
/**
|
|
8
|
-
* The name of the app. This comes from the `name` in your `sst.json`.
|
|
9
|
-
*/
|
|
10
|
-
name;
|
|
11
|
-
/**
|
|
12
|
-
* The stage the app is being deployed to. If this is not specified as the [`--stage`](/packages/sst.md#--stage) option, it'll default to the stage configured during the initial run of the SST CLI.
|
|
13
|
-
*/
|
|
14
|
-
stage;
|
|
15
|
-
/**
|
|
16
|
-
* The region the app is being deployed to. If this is not specified as the [`--region`](/packages/sst.md#--region) option in the SST CLI, it'll default to the `region` in your `sst.json`.
|
|
17
|
-
*/
|
|
18
|
-
region;
|
|
19
|
-
/**
|
|
20
|
-
* The AWS account the app is being deployed to. This comes from the IAM credentials being used to run the SST CLI.
|
|
21
|
-
*/
|
|
22
|
-
account;
|
|
23
|
-
/**
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
constructor(deployProps) {
|
|
27
|
-
super();
|
|
28
|
-
this.name = deployProps.name;
|
|
29
|
-
this.stage = deployProps.stage;
|
|
30
|
-
this.region = deployProps.region;
|
|
31
|
-
this.account = process.env.CDK_DEFAULT_ACCOUNT || "my-account";
|
|
32
|
-
}
|
|
33
|
-
synth(options = {}) {
|
|
34
|
-
// Check app has stack
|
|
35
|
-
const stacks = this.node.children.filter((child) => isSSTDebugStack(child));
|
|
36
|
-
if (stacks.length > 1) {
|
|
37
|
-
console.error(`Error: You can only create 1 DebugStack inside the "debugApp()" callback.\n`);
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
if (stacks.length === 0) {
|
|
41
|
-
console.error(`Error: The "debugApp()" callback is not creating a DebugStack.\n`);
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
for (const child of this.node.children) {
|
|
45
|
-
if (isStackConstruct(child)) {
|
|
46
|
-
// Stack names need to be parameterized with the stage name
|
|
47
|
-
if (!child.stackName.startsWith(`${this.stage}-`) &&
|
|
48
|
-
!child.stackName.endsWith(`-${this.stage}`) &&
|
|
49
|
-
child.stackName.indexOf(`-${this.stage}-`) === -1) {
|
|
50
|
-
console.error(`Error: Stack "${child.stackName}" is not parameterized with the stage name. The stack name needs to either start with "$stage-", end in "-$stage", or contain the stage name "-$stage-".\n`);
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return super.synth(options);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Use this method to prefix resource names in your stacks to make sure they don't thrash when deployed to different stages in the same AWS account. This method will prefix a given resource name with the stage and app name. Using the format `${stage}-${name}-${logicalName}`.
|
|
59
|
-
*/
|
|
60
|
-
logicalPrefixedName(logicalName) {
|
|
61
|
-
return `${this.stage}-${this.name}-${logicalName}`;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Construct } from "constructs";
|
|
2
|
-
import * as cdk from "aws-cdk-lib";
|
|
3
|
-
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
|
|
4
|
-
/**
|
|
5
|
-
* Stack properties for the DebugStack.
|
|
6
|
-
*/
|
|
7
|
-
export interface DebugStackProps extends cdk.StackProps {
|
|
8
|
-
/**
|
|
9
|
-
* S3 bucket to store large websocket payloads.
|
|
10
|
-
*/
|
|
11
|
-
payloadBucketArn?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Lambda function props for WebSocket request handlers.
|
|
14
|
-
*/
|
|
15
|
-
websocketHandlerRoleArn?: string;
|
|
16
|
-
cdk?: {
|
|
17
|
-
/**
|
|
18
|
-
* Override the settings of the internally created DynamoDB table
|
|
19
|
-
*/
|
|
20
|
-
table?: Omit<dynamodb.TableProps, "partitionKey" | "sortKey">;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* The `DebugStack` construct is used internally to create the resources needed to power Live Lambda Development. Note that, the `DebugStack` construct should only be created inside the [`DebugApp`](DebugApp).
|
|
25
|
-
*/
|
|
26
|
-
export declare class DebugStack extends cdk.Stack {
|
|
27
|
-
readonly stage: string;
|
|
28
|
-
private readonly api;
|
|
29
|
-
private readonly table;
|
|
30
|
-
private readonly bucket;
|
|
31
|
-
constructor(scope: Construct, id: string, props?: DebugStackProps);
|
|
32
|
-
private addApiRoute;
|
|
33
|
-
private static checkForEnvInProps;
|
|
34
|
-
}
|
package/constructs/DebugStack.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
import url from "url";
|
|
3
|
-
import * as cdk from "aws-cdk-lib";
|
|
4
|
-
import * as s3 from "aws-cdk-lib/aws-s3";
|
|
5
|
-
import * as iam from "aws-cdk-lib/aws-iam";
|
|
6
|
-
import * as logs from "aws-cdk-lib/aws-logs";
|
|
7
|
-
import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
8
|
-
import * as apig from "aws-cdk-lib/aws-apigatewayv2";
|
|
9
|
-
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
|
|
10
|
-
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
11
|
-
/**
|
|
12
|
-
* The `DebugStack` construct is used internally to create the resources needed to power Live Lambda Development. Note that, the `DebugStack` construct should only be created inside the [`DebugApp`](DebugApp).
|
|
13
|
-
*/
|
|
14
|
-
export class DebugStack extends cdk.Stack {
|
|
15
|
-
stage;
|
|
16
|
-
api;
|
|
17
|
-
table;
|
|
18
|
-
bucket;
|
|
19
|
-
constructor(scope, id, props) {
|
|
20
|
-
const app = scope.node.root;
|
|
21
|
-
const stackId = app.logicalPrefixedName(id);
|
|
22
|
-
DebugStack.checkForEnvInProps(id, props);
|
|
23
|
-
super(scope, stackId, {
|
|
24
|
-
...props,
|
|
25
|
-
env: {
|
|
26
|
-
account: app.account,
|
|
27
|
-
region: app.region,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
this.stage = app.stage;
|
|
31
|
-
// Create connection table
|
|
32
|
-
this.table = new dynamodb.Table(this, "Table", {
|
|
33
|
-
partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
|
|
34
|
-
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
|
|
35
|
-
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
36
|
-
...props?.cdk?.table,
|
|
37
|
-
});
|
|
38
|
-
// Create S3 bucket for storing large payloads
|
|
39
|
-
this.bucket = props?.payloadBucketArn
|
|
40
|
-
? s3.Bucket.fromBucketArn(this, "Bucket", props.payloadBucketArn)
|
|
41
|
-
: new s3.Bucket(this, "Bucket", {
|
|
42
|
-
lifecycleRules: [
|
|
43
|
-
{
|
|
44
|
-
expiration: cdk.Duration.days(1),
|
|
45
|
-
prefix: "payloads/",
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
encryption: s3.BucketEncryption.S3_MANAGED,
|
|
49
|
-
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
50
|
-
autoDeleteObjects: true,
|
|
51
|
-
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
|
|
52
|
-
});
|
|
53
|
-
// Create API
|
|
54
|
-
this.api = new apig.CfnApi(this, "Api", {
|
|
55
|
-
name: `${this.stackName}-api`,
|
|
56
|
-
protocolType: "WEBSOCKET",
|
|
57
|
-
routeSelectionExpression: "$request.body.action",
|
|
58
|
-
});
|
|
59
|
-
new apig.CfnStage(this, "ApiStage", {
|
|
60
|
-
apiId: this.api.ref,
|
|
61
|
-
autoDeploy: true,
|
|
62
|
-
stageName: this.stage,
|
|
63
|
-
});
|
|
64
|
-
// Create API routes
|
|
65
|
-
const role = props?.websocketHandlerRoleArn
|
|
66
|
-
? iam.Role.fromRoleArn(this, "HandlerRole", props.websocketHandlerRoleArn)
|
|
67
|
-
: undefined;
|
|
68
|
-
this.addApiRoute("Connect", "$connect", "wsConnect.main", role);
|
|
69
|
-
this.addApiRoute("Disconnect", "$disconnect", "wsDisconnect.main", role);
|
|
70
|
-
this.addApiRoute("Default", "$default", "wsDefault.main", role);
|
|
71
|
-
// Stack Output
|
|
72
|
-
new cdk.CfnOutput(this, "Endpoint", {
|
|
73
|
-
value: `${this.api.attrApiEndpoint}/${this.stage}`,
|
|
74
|
-
});
|
|
75
|
-
new cdk.CfnOutput(this, "BucketArn", {
|
|
76
|
-
value: this.bucket.bucketArn,
|
|
77
|
-
});
|
|
78
|
-
new cdk.CfnOutput(this, "BucketName", {
|
|
79
|
-
value: this.bucket.bucketName,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
addApiRoute(id, routeKey, handler, role) {
|
|
83
|
-
// Create execution policy
|
|
84
|
-
const policyStatement = new iam.PolicyStatement();
|
|
85
|
-
policyStatement.addAllResources();
|
|
86
|
-
policyStatement.addActions("apigateway:*", "dynamodb:*", "execute-api:ManageConnections");
|
|
87
|
-
// Create Lambda
|
|
88
|
-
const lambdaFunc = new lambda.Function(this, id, {
|
|
89
|
-
code: lambda.Code.fromAsset(path.join(__dirname, "../assets/DebugStack")),
|
|
90
|
-
handler,
|
|
91
|
-
runtime: lambda.Runtime.NODEJS_16_X,
|
|
92
|
-
timeout: cdk.Duration.seconds(10),
|
|
93
|
-
memorySize: 256,
|
|
94
|
-
logRetention: logs.RetentionDays.ONE_WEEK,
|
|
95
|
-
logRetentionRole: role,
|
|
96
|
-
environment: {
|
|
97
|
-
TABLE_NAME: this.table.tableName,
|
|
98
|
-
},
|
|
99
|
-
role,
|
|
100
|
-
initialPolicy: [policyStatement],
|
|
101
|
-
});
|
|
102
|
-
lambdaFunc.addPermission(`${id}Permission`, {
|
|
103
|
-
principal: new iam.ServicePrincipal("apigateway.amazonaws.com"),
|
|
104
|
-
});
|
|
105
|
-
// Create API integrations
|
|
106
|
-
const integration = new apig.CfnIntegration(this, `${id}Integration`, {
|
|
107
|
-
apiId: this.api.ref,
|
|
108
|
-
integrationType: "AWS_PROXY",
|
|
109
|
-
integrationUri: `arn:${this.partition}:apigateway:${this.region}:lambda:path/2015-03-31/functions/${lambdaFunc.functionArn}/invocations`,
|
|
110
|
-
});
|
|
111
|
-
// Create API routes
|
|
112
|
-
new apig.CfnRoute(this, `${id}Route`, {
|
|
113
|
-
apiId: this.api.ref,
|
|
114
|
-
routeKey,
|
|
115
|
-
authorizationType: "NONE",
|
|
116
|
-
target: `integrations/${integration.ref}`,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
-
static checkForEnvInProps(id, props) {
|
|
121
|
-
if (props && props.env) {
|
|
122
|
-
let envS = "";
|
|
123
|
-
try {
|
|
124
|
-
envS = " (" + JSON.stringify(props.env) + ")";
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
// Ignore
|
|
128
|
-
}
|
|
129
|
-
throw new Error(`Do not set the "env" prop while initializing "${id}" stack${envS}. Use the "AWS_PROFILE" environment variable and "--region" CLI option instead.`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|