sst 2.1.35 → 2.2.1

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.
Files changed (41) hide show
  1. package/bootstrap.js +1 -1
  2. package/cdk/cloudformation-deployments-wrapper.d.ts +1 -1
  3. package/cdk/cloudformation-deployments-wrapper.js +6 -6
  4. package/cdk/cloudformation-deployments.d.ts +8 -8
  5. package/cdk/cloudformation-deployments.js +7 -7
  6. package/cdk/deploy-stack.d.ts +6 -6
  7. package/cdk/deploy-stack.js +9 -9
  8. package/cli/colors.d.ts +9 -20
  9. package/cli/commands/deploy.js +8 -6
  10. package/cli/commands/remove.js +1 -1
  11. package/cli/ui/deploy.d.ts +1 -0
  12. package/cli/ui/deploy.js +1 -1
  13. package/constructs/App.d.ts +4 -27
  14. package/constructs/App.js +5 -31
  15. package/constructs/Cron.d.ts +1 -1
  16. package/constructs/EventBus.d.ts +68 -35
  17. package/constructs/EventBus.js +13 -4
  18. package/constructs/Function.js +36 -33
  19. package/constructs/Job.js +6 -5
  20. package/constructs/RDS.js +4 -8
  21. package/constructs/Script.js +1 -1
  22. package/constructs/SsrSite.js +3 -1
  23. package/constructs/Stack.d.ts +8 -0
  24. package/constructs/Stack.js +17 -8
  25. package/constructs/StaticSite.js +3 -1
  26. package/constructs/deprecated/NextjsSite.js +2 -1
  27. package/credentials.d.ts +1 -1
  28. package/credentials.js +1 -1
  29. package/node/future/auth/index.d.ts +1 -0
  30. package/node/future/auth/session.js +1 -8
  31. package/package.json +8 -12
  32. package/runtime/handlers/node.js +0 -1
  33. package/runtime/server.js +4 -2
  34. package/sst.mjs +40 -37
  35. package/stacks/synth.d.ts +1 -1
  36. package/stacks/synth.js +3 -3
  37. package/support/bootstrap-metadata-function/index.mjs +1027 -274
  38. package/support/bridge/bridge.mjs +46 -35
  39. package/support/custom-resources/index.mjs +1663 -910
  40. package/support/nodejs-runtime/index.mjs +38 -2
  41. package/support/python-runtime/runtime.py +10 -4
package/bootstrap.js CHANGED
@@ -146,7 +146,7 @@ export async function bootstrapSST() {
146
146
  const fn = new Function(stack, "MetadataHandler", {
147
147
  code: Code.fromAsset(path.resolve(__dirname, "support/bootstrap-metadata-function")),
148
148
  handler: "index.handler",
149
- runtime: region?.startsWith("us-gov-")
149
+ runtime: region?.startsWith("us-gov-") || region?.startsWith("cn-")
150
150
  ? Runtime.NODEJS_16_X
151
151
  : Runtime.NODEJS_18_X,
152
152
  environment: {
@@ -1,3 +1,3 @@
1
- import { SdkProvider } from "aws-cdk/lib/api/aws-auth/sdk-provider.js";
1
+ import { SdkProvider } from "sst-aws-cdk/lib/api/aws-auth/sdk-provider.js";
2
2
  import { DeployStackOptions as PublishStackAssetsOptions } from "./cloudformation-deployments.js";
3
3
  export declare function publishDeployAssets(sdkProvider: SdkProvider, options: PublishStackAssetsOptions): Promise<any>;
@@ -1,9 +1,9 @@
1
- import { debug } from "aws-cdk/lib/logging.js";
2
- import { CloudFormationStack, TemplateParameters, waitForStackDelete, } from "aws-cdk/lib/api/util/cloudformation.js";
3
- import { ToolkitInfo } from "aws-cdk/lib/api/toolkit-info.js";
4
- import { addMetadataAssetsToManifest } from "aws-cdk/lib/assets.js";
5
- import { publishAssets } from "aws-cdk/lib/util/asset-publishing.js";
6
- import { AssetManifestBuilder } from "aws-cdk/lib/util/asset-manifest-builder.js";
1
+ import { debug } from "sst-aws-cdk/lib/logging.js";
2
+ import { CloudFormationStack, TemplateParameters, waitForStackDelete, } from "sst-aws-cdk/lib/api/util/cloudformation.js";
3
+ import { ToolkitInfo } from "sst-aws-cdk/lib/api/toolkit-info.js";
4
+ import { addMetadataAssetsToManifest } from "sst-aws-cdk/lib/assets.js";
5
+ import { publishAssets } from "sst-aws-cdk/lib/util/asset-publishing.js";
6
+ import { AssetManifestBuilder } from "sst-aws-cdk/lib/util/asset-manifest-builder.js";
7
7
  import { CloudFormationDeployments, } from "./cloudformation-deployments.js";
8
8
  import { makeBodyParameter } from "./deploy-stack.js";
9
9
  import { Context } from "../context/context.js";
@@ -1,13 +1,13 @@
1
1
  import * as cxapi from "@aws-cdk/cx-api";
2
- import { Tag } from "aws-cdk/lib/cdk-toolkit.js";
3
- import { BuildAssetsOptions, PublishAssetsOptions } from "aws-cdk/lib/util/asset-publishing.js";
4
- import { Mode } from "aws-cdk/lib/api/aws-auth/credentials.js";
5
- import { ISDK } from "aws-cdk/lib/api/aws-auth/sdk.js";
6
- import { SdkProvider } from "aws-cdk/lib/api/aws-auth/sdk-provider.js";
2
+ import { Tag } from "sst-aws-cdk/lib/cdk-toolkit.js";
3
+ import { BuildAssetsOptions, PublishAssetsOptions } from "sst-aws-cdk/lib/util/asset-publishing.js";
4
+ import { Mode } from "sst-aws-cdk/lib/api/aws-auth/credentials.js";
5
+ import { ISDK } from "sst-aws-cdk/lib/api/aws-auth/sdk.js";
6
+ import { SdkProvider } from "sst-aws-cdk/lib/api/aws-auth/sdk-provider.js";
7
7
  import { DeployStackResult, DeploymentMethod } from "./deploy-stack.js";
8
- import { ToolkitInfo } from "aws-cdk/lib/api/toolkit-info.js";
9
- import { Template, ResourcesToImport, ResourceIdentifierSummaries } from "aws-cdk/lib/api/util/cloudformation.js";
10
- import { StackActivityProgress } from "aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.js";
8
+ import { ToolkitInfo } from "sst-aws-cdk/lib/api/toolkit-info.js";
9
+ import { Template, ResourcesToImport, ResourceIdentifierSummaries } from "sst-aws-cdk/lib/api/util/cloudformation.js";
10
+ import { StackActivityProgress } from "sst-aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.js";
11
11
  /**
12
12
  * SDK obtained by assuming the lookup role
13
13
  * for a given environment
@@ -1,14 +1,14 @@
1
1
  // Copied from https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk/lib/api/cloudformation-deployments.ts
2
2
  import * as cxapi from "@aws-cdk/cx-api";
3
3
  import { AssetManifest } from "cdk-assets";
4
- import { debug, warning } from "aws-cdk/lib/logging.js";
5
- import { buildAssets, publishAssets, } from "aws-cdk/lib/util/asset-publishing.js";
6
- import { Mode } from "aws-cdk/lib/api/aws-auth/credentials.js";
4
+ import { debug, warning } from "sst-aws-cdk/lib/logging.js";
5
+ import { buildAssets, publishAssets, } from "sst-aws-cdk/lib/util/asset-publishing.js";
6
+ import { Mode } from "sst-aws-cdk/lib/api/aws-auth/credentials.js";
7
7
  import { deployStack, destroyStack, makeBodyParameterAndUpload, } from "./deploy-stack.js";
8
- import { loadCurrentTemplateWithNestedStacks, loadCurrentTemplate, } from "aws-cdk/lib/api/nested-stack-helpers.js";
9
- import { ToolkitInfo } from "aws-cdk/lib/api/toolkit-info.js";
10
- import { CloudFormationStack, } from "aws-cdk/lib/api/util/cloudformation.js";
11
- import { replaceEnvPlaceholders } from "aws-cdk/lib/api/util/placeholders.js";
8
+ import { loadCurrentTemplateWithNestedStacks, loadCurrentTemplate, } from "sst-aws-cdk/lib/api/nested-stack-helpers.js";
9
+ import { ToolkitInfo } from "sst-aws-cdk/lib/api/toolkit-info.js";
10
+ import { CloudFormationStack, } from "sst-aws-cdk/lib/api/util/cloudformation.js";
11
+ import { replaceEnvPlaceholders } from "sst-aws-cdk/lib/api/util/placeholders.js";
12
12
  import { callWithRetry } from "./util.js";
13
13
  /**
14
14
  * Try to use the bootstrap lookupRole. There are two scenarios that are handled here
@@ -1,10 +1,10 @@
1
1
  import * as cxapi from "@aws-cdk/cx-api";
2
- import { Tag } from "aws-cdk/lib/cdk-toolkit.js";
3
- import { AssetManifestBuilder } from "aws-cdk/lib/util/asset-manifest-builder.js";
4
- import { ISDK, SdkProvider } from "aws-cdk/lib/api/aws-auth/index.js";
5
- import { ToolkitInfo } from "aws-cdk/lib/api/toolkit-info.js";
6
- import { ResourcesToImport } from "aws-cdk/lib/api/util/cloudformation.js";
7
- import { StackActivityProgress } from "aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.js";
2
+ import { Tag } from "sst-aws-cdk/lib/cdk-toolkit.js";
3
+ import { AssetManifestBuilder } from "sst-aws-cdk/lib/util/asset-manifest-builder.js";
4
+ import { ISDK, SdkProvider } from "sst-aws-cdk/lib/api/aws-auth/index.js";
5
+ import { ToolkitInfo } from "sst-aws-cdk/lib/api/toolkit-info.js";
6
+ import { ResourcesToImport } from "sst-aws-cdk/lib/api/util/cloudformation.js";
7
+ import { StackActivityProgress } from "sst-aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.js";
8
8
  type TemplateBodyParameter = {
9
9
  TemplateBody?: string;
10
10
  TemplateURL?: string;
@@ -1,15 +1,15 @@
1
1
  import * as cxapi from "@aws-cdk/cx-api";
2
2
  import fs from "fs/promises";
3
3
  import * as uuid from "uuid";
4
- import { addMetadataAssetsToManifest } from "aws-cdk/lib/assets.js";
5
- import { debug, error, print } from "aws-cdk/lib/logging.js";
6
- import { toYAML } from "aws-cdk/lib/serialize.js";
7
- import { AssetManifestBuilder } from "aws-cdk/lib/util/asset-manifest-builder.js";
8
- import { publishAssets } from "aws-cdk/lib/util/asset-publishing.js";
9
- import { contentHash } from "aws-cdk/lib/util/content-hash.js";
10
- import { CfnEvaluationException } from "aws-cdk/lib/api/evaluate-cloudformation-template.js";
11
- import { tryHotswapDeployment } from "aws-cdk/lib/api/hotswap-deployments.js";
12
- import { changeSetHasNoChanges, CloudFormationStack, TemplateParameters, waitForChangeSet, waitForStackDeploy, waitForStackDelete, } from "aws-cdk/lib/api/util/cloudformation.js";
4
+ import { addMetadataAssetsToManifest } from "sst-aws-cdk/lib/assets.js";
5
+ import { debug, error, print } from "sst-aws-cdk/lib/logging.js";
6
+ import { toYAML } from "sst-aws-cdk/lib/serialize.js";
7
+ import { AssetManifestBuilder } from "sst-aws-cdk/lib/util/asset-manifest-builder.js";
8
+ import { publishAssets } from "sst-aws-cdk/lib/util/asset-publishing.js";
9
+ import { contentHash } from "sst-aws-cdk/lib/util/content-hash.js";
10
+ import { CfnEvaluationException } from "sst-aws-cdk/lib/api/evaluate-cloudformation-template.js";
11
+ import { tryHotswapDeployment } from "sst-aws-cdk/lib/api/hotswap-deployments.js";
12
+ import { changeSetHasNoChanges, CloudFormationStack, TemplateParameters, waitForChangeSet, waitForStackDeploy, waitForStackDelete, } from "sst-aws-cdk/lib/api/util/cloudformation.js";
13
13
  import { blue } from "colorette";
14
14
  import { callWithRetry } from "./util.js";
15
15
  const LARGE_TEMPLATE_SIZE_KB = 50;
package/cli/colors.d.ts CHANGED
@@ -1,28 +1,17 @@
1
- import chalk from "chalk";
2
1
  declare let last: "line" | "gap";
3
2
  export declare const Colors: {
4
3
  line: (message?: any, ...optionalParams: any[]) => void;
5
4
  mode(input: typeof last): void;
6
5
  gap(): void;
7
- hex: (color: string) => chalk.Chalk;
8
- primary: chalk.Chalk;
9
- link: chalk.Chalk;
10
- success: chalk.Chalk;
11
- danger: chalk.Chalk;
12
- warning: chalk.Chalk;
13
- dim: chalk.Chalk;
14
- bold: chalk.Chalk;
15
- all: chalk.Chalk & chalk.ChalkFunction & {
16
- supportsColor: false | chalk.ColorSupport;
17
- Level: chalk.Level;
18
- Color: ("red" | "green" | "yellow" | "black" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright") | ("bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "bgGray" | "bgGrey" | "bgBlackBright" | "bgRedBright" | "bgGreenBright" | "bgYellowBright" | "bgBlueBright" | "bgMagentaBright" | "bgCyanBright" | "bgWhiteBright");
19
- ForegroundColor: "red" | "green" | "yellow" | "black" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright";
20
- BackgroundColor: "bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "bgGray" | "bgGrey" | "bgBlackBright" | "bgRedBright" | "bgGreenBright" | "bgYellowBright" | "bgBlueBright" | "bgMagentaBright" | "bgCyanBright" | "bgWhiteBright";
21
- Modifiers: "bold" | "dim" | "reset" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough" | "visible";
22
- stderr: chalk.Chalk & {
23
- supportsColor: false | chalk.ColorSupport;
24
- };
25
- };
6
+ hex: (color: string) => import("chalk").ChalkInstance;
7
+ primary: import("chalk").ChalkInstance;
8
+ link: import("chalk").ChalkInstance;
9
+ success: import("chalk").ChalkInstance;
10
+ danger: import("chalk").ChalkInstance;
11
+ warning: import("chalk").ChalkInstance;
12
+ dim: import("chalk").ChalkInstance;
13
+ bold: import("chalk").ChalkInstance;
14
+ all: import("chalk").ChalkInstance;
26
15
  prefix: string;
27
16
  };
28
17
  export {};
@@ -38,6 +38,12 @@ export const deploy = (program) => program.command("deploy [filter]", "Deploy yo
38
38
  Colors.line(` ${Colors.bold("Region:")} ${project.config.region}`);
39
39
  Colors.line(` ${Colors.bold("Account:")} ${identity.Account}`);
40
40
  Colors.gap();
41
+ const isActiveStack = (stackId) => !args.filter ||
42
+ stackId
43
+ .toLowerCase()
44
+ .replace(project.config.name.toLowerCase(), "")
45
+ .replace(project.config.stage.toLowerCase(), "")
46
+ .includes(args.filter.toLowerCase());
41
47
  // Generate cloud assembly
42
48
  // - if --from is specified, we will use the existing cloud assembly
43
49
  // - if --from is not specified, we will call synth to generate
@@ -52,16 +58,12 @@ export const deploy = (program) => program.command("deploy [filter]", "Deploy yo
52
58
  const result = await Stacks.synth({
53
59
  fn: project.stacks,
54
60
  mode: "deploy",
61
+ isActiveStack,
55
62
  });
56
63
  spinner.succeed();
57
64
  return result;
58
65
  })();
59
- const target = assembly.stacks.filter((s) => !args.filter ||
60
- s.id
61
- .toLowerCase()
62
- .replace(project.config.name.toLowerCase(), "")
63
- .replace(project.config.stage.toLowerCase(), "")
64
- .includes(args.filter.toLowerCase()));
66
+ const target = assembly.stacks.filter((s) => isActiveStack(s.id));
65
67
  if (!target.length) {
66
68
  Colors.line(`No stacks found matching ${blue(args.filter)}`);
67
69
  process.exit(1);
@@ -39,7 +39,7 @@ export const remove = (program) => program.command("remove [filter]", "Remove yo
39
39
  console.log(`No stacks found matching ${blue(args.filter)}`);
40
40
  process.exit(1);
41
41
  }
42
- const component = render(React.createElement(DeploymentUI, { assembly: assembly }));
42
+ const component = render(React.createElement(DeploymentUI, { assembly: assembly, remove: true }));
43
43
  const results = await Stacks.removeMany(target);
44
44
  component.clear();
45
45
  component.unmount();
@@ -3,6 +3,7 @@ import { Stacks } from "../../stacks/index.js";
3
3
  import type { CloudAssembly } from "aws-cdk-lib/cx-api";
4
4
  interface Props {
5
5
  assembly: CloudAssembly;
6
+ remove?: boolean;
6
7
  }
7
8
  export declare const DeploymentUI: (props: Props) => JSX.Element;
8
9
  export declare function printDeploymentResults(assembly: CloudAssembly, results: Awaited<ReturnType<typeof Stacks.deployMany>>, remove?: boolean): void;
package/cli/ui/deploy.js CHANGED
@@ -64,7 +64,7 @@ export const DeploymentUI = (props) => {
64
64
  React.createElement(Text, null,
65
65
  React.createElement(Spinner, null),
66
66
  " ",
67
- React.createElement(Text, { dimColor: true }, "Deploying..."))))));
67
+ React.createElement(Text, { dimColor: true }, props.remove ? "Removing..." : "Deploying..."))))));
68
68
  };
69
69
  export function printDeploymentResults(assembly, results, remove) {
70
70
  // Print success stacks
@@ -29,15 +29,11 @@ export interface AppDeployProps {
29
29
  */
30
30
  readonly region?: string;
31
31
  readonly buildDir?: string;
32
- readonly skipBuild?: boolean;
33
32
  readonly account?: string;
34
- readonly debugEndpoint?: string;
35
- readonly debugBucketArn?: string;
36
- readonly debugBucketName?: string;
37
33
  readonly debugStartedAt?: number;
38
- readonly debugBridge?: string;
39
34
  readonly debugIncreaseTimeout?: boolean;
40
35
  readonly mode: "deploy" | "dev" | "remove";
36
+ readonly isActiveStack?: (stackName: string) => boolean;
41
37
  }
42
38
  type AppRemovalPolicy = Lowercase<RemovalPolicy>;
43
39
  export type AppProps = CDKAppProps;
@@ -70,37 +66,18 @@ export declare class App extends CDKApp {
70
66
  */
71
67
  readonly account: string;
72
68
  /** @internal */
73
- readonly debugBridge?: string;
74
- /** @internal */
75
- readonly debugEndpoint?: string;
76
- /** @internal */
77
- readonly debugBucketArn?: string;
78
- /** @internal */
79
- readonly debugBucketName?: string;
80
- /** @internal */
81
69
  readonly debugStartedAt?: number;
82
70
  /** @internal */
83
71
  readonly debugIncreaseTimeout?: boolean;
84
72
  /** @internal */
85
73
  readonly appPath: string;
86
74
  /** @internal */
75
+ readonly isActiveStack?: (stackName: string) => boolean;
76
+ /** @internal */
87
77
  defaultFunctionProps: (FunctionProps | ((stack: Stack) => FunctionProps))[];
88
78
  private _defaultRemovalPolicy?;
89
79
  /** @internal */
90
80
  get defaultRemovalPolicy(): "destroy" | "retain" | "snapshot" | undefined;
91
- /**
92
- * Skip building Function code
93
- * Note that on `sst remove`, we do not want to bundle the Lambda functions.
94
- * CDK disables bundling (ie. zipping) for `cdk destroy` command.
95
- * But SST runs `cdk synth` first then manually remove each stack. Hence
96
- * we cannot rely on CDK to disable bundling, and we disable it manually.
97
- * This allows us to disable BOTH building and bundling, where as CDK
98
- * would only disable the latter. For example, `cdk destroy` still trys
99
- * to install Python dependencies in Docker.
100
- *
101
- * @internal
102
- */
103
- readonly skipBuild: boolean;
104
81
  /**
105
82
  * @internal
106
83
  */
@@ -122,7 +99,7 @@ export declare class App extends CDKApp {
122
99
  * :::
123
100
  * @example
124
101
  * ```js
125
- * app.setDefaultRemovalPolicy(app.local ? "destroy" : "retain")
102
+ * app.setDefaultRemovalPolicy(app.mode === "dev" ? "destroy" : "retain")
126
103
  * ```
127
104
  */
128
105
  setDefaultRemovalPolicy(policy: AppRemovalPolicy): void;
package/constructs/App.js CHANGED
@@ -51,39 +51,20 @@ export class App extends CDKApp {
51
51
  */
52
52
  account;
53
53
  /** @internal */
54
- debugBridge;
55
- /** @internal */
56
- debugEndpoint;
57
- /** @internal */
58
- debugBucketArn;
59
- /** @internal */
60
- debugBucketName;
61
- /** @internal */
62
54
  debugStartedAt;
63
55
  /** @internal */
64
56
  debugIncreaseTimeout;
65
57
  /** @internal */
66
58
  appPath;
67
59
  /** @internal */
60
+ isActiveStack;
61
+ /** @internal */
68
62
  defaultFunctionProps;
69
63
  _defaultRemovalPolicy;
70
64
  /** @internal */
71
65
  get defaultRemovalPolicy() {
72
66
  return this._defaultRemovalPolicy;
73
67
  }
74
- /**
75
- * Skip building Function code
76
- * Note that on `sst remove`, we do not want to bundle the Lambda functions.
77
- * CDK disables bundling (ie. zipping) for `cdk destroy` command.
78
- * But SST runs `cdk synth` first then manually remove each stack. Hence
79
- * we cannot rely on CDK to disable bundling, and we disable it manually.
80
- * This allows us to disable BOTH building and bundling, where as CDK
81
- * would only disable the latter. For example, `cdk destroy` still trys
82
- * to install Python dependencies in Docker.
83
- *
84
- * @internal
85
- */
86
- skipBuild;
87
68
  /**
88
69
  * @internal
89
70
  */
@@ -100,18 +81,11 @@ export class App extends CDKApp {
100
81
  deployProps.region || process.env.CDK_DEFAULT_REGION || "us-east-1";
101
82
  this.account =
102
83
  deployProps.account || process.env.CDK_DEFAULT_ACCOUNT || "my-account";
103
- this.skipBuild = deployProps.skipBuild || false;
84
+ this.isActiveStack = deployProps.isActiveStack;
104
85
  this.defaultFunctionProps = [];
105
- if (deployProps.debugEndpoint) {
106
- this.local = true;
107
- this.debugEndpoint = deployProps.debugEndpoint;
108
- this.debugBucketArn = deployProps.debugBucketArn;
109
- this.debugBucketName = deployProps.debugBucketName;
86
+ if (this.mode === "dev") {
110
87
  this.debugStartedAt = deployProps.debugStartedAt;
111
88
  this.debugIncreaseTimeout = deployProps.debugIncreaseTimeout;
112
- if (deployProps.debugBridge) {
113
- this.debugBridge = deployProps.debugBridge;
114
- }
115
89
  }
116
90
  }
117
91
  /**
@@ -134,7 +108,7 @@ export class App extends CDKApp {
134
108
  * :::
135
109
  * @example
136
110
  * ```js
137
- * app.setDefaultRemovalPolicy(app.local ? "destroy" : "retain")
111
+ * app.setDefaultRemovalPolicy(app.mode === "dev" ? "destroy" : "retain")
138
112
  * ```
139
113
  */
140
114
  setDefaultRemovalPolicy(policy) {
@@ -80,7 +80,7 @@ export interface CronProps {
80
80
  * new Cron(stack, "Cron", {
81
81
  * job: "src/lambda.main",
82
82
  * schedule: "rate(5 minutes)",
83
- * enabled: app.local,
83
+ * enabled: app.mode === "dev",
84
84
  * })
85
85
  * ```
86
86
  */
@@ -1,7 +1,8 @@
1
1
  import { Construct } from "constructs";
2
2
  import * as lambda from "aws-cdk-lib/aws-lambda";
3
3
  import * as events from "aws-cdk-lib/aws-events";
4
- import * as eventsTargets from "aws-cdk-lib/aws-events-targets";
4
+ import { LambdaFunctionProps as LambdaFunctionTargetProps, SqsQueueProps as SqsQueueTargetProps, LogGroupProps as LogGroupTargetProps } from "aws-cdk-lib/aws-events-targets";
5
+ import { ILogGroup } from "aws-cdk-lib/aws-logs";
5
6
  import { Queue } from "./Queue.js";
6
7
  import { SSTConstruct } from "./Construct.js";
7
8
  import { FunctionProps, FunctionInlineDefinition, FunctionDefinition } from "./Function.js";
@@ -9,6 +10,18 @@ import { FunctionBindingProps } from "./util/functionBinding.js";
9
10
  import { Permissions } from "./util/permission.js";
10
11
  /**
11
12
  * Used to configure an EventBus function target
13
+ * @example
14
+ * ```js
15
+ * new EventBus(stack, "Bus", {
16
+ * rules: {
17
+ * myRule: {
18
+ * targets: {
19
+ * myTarget: { function: "src/function.handler" },
20
+ * }
21
+ * },
22
+ * },
23
+ * });
24
+ * ```
12
25
  */
13
26
  export interface EventBusFunctionTargetProps {
14
27
  /**
@@ -17,26 +30,31 @@ export interface EventBusFunctionTargetProps {
17
30
  type?: "function";
18
31
  /**
19
32
  * The function to trigger
20
- *
21
- * @example
22
- * ```js
23
- * new EventBus(stack, "Bus", {
24
- * rules: {
25
- * myRule: {
26
- * targets: {
27
- * myTarget: { function: "src/function.handler" },
28
- * }
29
- * },
30
- * },
31
- * });
32
- * ```
33
33
  */
34
34
  function?: FunctionDefinition;
35
35
  cdk?: {
36
36
  function?: lambda.IFunction;
37
- target?: eventsTargets.LambdaFunctionProps;
37
+ target?: LambdaFunctionTargetProps;
38
38
  };
39
39
  }
40
+ /**
41
+ * Used to configure an EventBus queue target
42
+ * @example
43
+ * ```js
44
+ * new EventBus(stack, "Bus", {
45
+ * rules: {
46
+ * myRule: {
47
+ * targets: {
48
+ * myTarget: {
49
+ * type: "queue",
50
+ * queue: new Queue(stack, "Queue")
51
+ * }
52
+ * }
53
+ * },
54
+ * },
55
+ * });
56
+ * ```
57
+ */
40
58
  export interface EventBusQueueTargetProps {
41
59
  /**
42
60
  * String literal to signify that the target is a queue
@@ -44,26 +62,40 @@ export interface EventBusQueueTargetProps {
44
62
  type: "queue";
45
63
  /**
46
64
  * The queue to trigger
47
- *
48
- * @example
49
- * ```js
50
- * new EventBus(stack, "Bus", {
51
- * rules: {
52
- * myRule: {
53
- * targets: {
54
- * myTarget: {
55
- * type: "queue",
56
- * queue: new Queue(stack, "Queue")
57
- * }
58
- * }
59
- * },
60
- * },
61
- * });
62
- * ```
63
65
  */
64
66
  queue: Queue;
65
67
  cdk?: {
66
- target?: eventsTargets.SqsQueueProps;
68
+ target?: SqsQueueTargetProps;
69
+ };
70
+ }
71
+ /**
72
+ * Used to configure an EventBus log group target
73
+ * @example
74
+ * ```js
75
+ * new EventBus(stack, "Bus", {
76
+ * rules: {
77
+ * myRule: {
78
+ * targets: {
79
+ * myTarget: {
80
+ * type: "log_group",
81
+ * cdk: {
82
+ * logGroup: LogGroup.fromLogGroupName(stack, "Logs", "/my/target/log"),
83
+ * }
84
+ * }
85
+ * }
86
+ * },
87
+ * },
88
+ * });
89
+ * ```
90
+ */
91
+ export interface EventBusLogGroupTargetProps {
92
+ /**
93
+ * String literal to signify that the target is a log group
94
+ */
95
+ type: "log_group";
96
+ cdk: {
97
+ logGroup: ILogGroup;
98
+ target?: LogGroupTargetProps;
67
99
  };
68
100
  }
69
101
  /**
@@ -120,7 +152,7 @@ export interface EventBusRuleProps {
120
152
  detailType?: string[];
121
153
  };
122
154
  /**
123
- * Configure targets for this rule. Can be a function or queue
155
+ * Configure targets for this rule.
124
156
  *
125
157
  * @example
126
158
  * ```js
@@ -136,7 +168,7 @@ export interface EventBusRuleProps {
136
168
  * });
137
169
  * ```
138
170
  */
139
- targets?: Record<string, FunctionInlineDefinition | EventBusFunctionTargetProps | Queue | EventBusQueueTargetProps>;
171
+ targets?: Record<string, FunctionInlineDefinition | EventBusFunctionTargetProps | Queue | EventBusQueueTargetProps | EventBusLogGroupTargetProps>;
140
172
  cdk?: {
141
173
  /**
142
174
  * Configure the internally created CDK `Rule` instance.
@@ -300,7 +332,7 @@ export declare class EventBus extends Construct implements SSTConstruct {
300
332
  * });
301
333
  * ```
302
334
  */
303
- addTargets(scope: Construct, ruleKey: string, targets: Record<string, FunctionInlineDefinition | EventBusFunctionTargetProps | Queue | EventBusQueueTargetProps>): void;
335
+ addTargets(scope: Construct, ruleKey: string, targets: Record<string, FunctionInlineDefinition | EventBusFunctionTargetProps | Queue | EventBusQueueTargetProps | EventBusLogGroupTargetProps>): void;
304
336
  /**
305
337
  * Binds the given list of resources to all event targets in this EventBus.
306
338
  *
@@ -381,6 +413,7 @@ export declare class EventBus extends Construct implements SSTConstruct {
381
413
  private addRule;
382
414
  private addTarget;
383
415
  private addQueueTarget;
416
+ private addLogGroupTarget;
384
417
  private addCdkFunctionTarget;
385
418
  private addFunctionTarget;
386
419
  }
@@ -1,6 +1,6 @@
1
1
  import { Construct } from "constructs";
2
2
  import * as events from "aws-cdk-lib/aws-events";
3
- import * as eventsTargets from "aws-cdk-lib/aws-events-targets";
3
+ import { LambdaFunction as LambdaFunctionTarget, SqsQueue as SqsQueueTarget, CloudWatchLogGroup as LogGroupTarget, } from "aws-cdk-lib/aws-events-targets";
4
4
  import { Queue } from "./Queue.js";
5
5
  import { getFunctionRef, isCDKConstruct } from "./Construct.js";
6
6
  import { Function as Fn, } from "./Function.js";
@@ -278,6 +278,10 @@ export class EventBus extends Construct {
278
278
  target = target;
279
279
  this.addQueueTarget(scope, ruleKey, eventsRule, targetName, target);
280
280
  }
281
+ else if (target.cdk?.logGroup) {
282
+ target = target;
283
+ this.addLogGroupTarget(scope, ruleKey, eventsRule, targetName, target);
284
+ }
281
285
  else if (target.cdk?.function) {
282
286
  target = target;
283
287
  this.addCdkFunctionTarget(scope, ruleKey, eventsRule, targetName, target);
@@ -302,7 +306,12 @@ export class EventBus extends Construct {
302
306
  }
303
307
  this.targetsData[ruleKey][targetName] = queue;
304
308
  // Create target
305
- eventsRule.addTarget(new eventsTargets.SqsQueue(queue.cdk.queue, targetProps));
309
+ eventsRule.addTarget(new SqsQueueTarget(queue.cdk.queue, targetProps));
310
+ }
311
+ addLogGroupTarget(scope, ruleKey, eventsRule, targetName, target) {
312
+ const { logGroup, target: targetProps } = target.cdk;
313
+ this.targetsData[ruleKey][targetName] = logGroup;
314
+ eventsRule.addTarget(new LogGroupTarget(logGroup, targetProps));
306
315
  }
307
316
  addCdkFunctionTarget(scope, ruleKey, eventsRule, targetName, target) {
308
317
  // Parse target props
@@ -310,7 +319,7 @@ export class EventBus extends Construct {
310
319
  const fn = target.cdk.function;
311
320
  this.targetsData[ruleKey][targetName] = fn;
312
321
  // Create target
313
- eventsRule.addTarget(new eventsTargets.LambdaFunction(fn, targetProps));
322
+ eventsRule.addTarget(new LambdaFunctionTarget(fn, targetProps));
314
323
  }
315
324
  addFunctionTarget(scope, ruleKey, eventsRule, targetName, target) {
316
325
  // Parse target props
@@ -329,7 +338,7 @@ export class EventBus extends Construct {
329
338
  const fn = Fn.fromDefinition(scope, `Target_${this.node.id}_${ruleKey}_${targetName}`, functionDefinition, this.props.defaults?.function, `The "defaults.function" cannot be applied if an instance of a Function construct is passed in. Make sure to define all the targets using FunctionProps, so the EventBus construct can apply the "defaults.function" to them.`);
330
339
  this.targetsData[ruleKey][targetName] = fn;
331
340
  // Create target
332
- eventsRule.addTarget(new eventsTargets.LambdaFunction(fn, targetProps));
341
+ eventsRule.addTarget(new LambdaFunctionTarget(fn, targetProps));
333
342
  // Attach existing permissions
334
343
  this.permissionsAttachedForAllTargets.forEach((permissions) => fn.attachPermissions(permissions));
335
344
  fn.bind(this.bindingForAllTargets);