sst 2.0.0-rc.9 → 2.0.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.
- package/bootstrap.d.ts +2 -4
- package/bootstrap.js +208 -61
- package/bus.d.ts +3 -3
- package/bus.js +1 -1
- package/cache.js +1 -1
- package/cdk/cloudformation-deployments-wrapper.d.ts +3 -0
- package/cdk/cloudformation-deployments-wrapper.js +117 -0
- package/cdk/cloudformation-deployments.d.ts +19 -4
- package/cdk/deploy-stack.d.ts +17 -2
- package/cdk/deploy-stack.js +6 -1
- package/cli/colors.d.ts +28 -0
- package/cli/colors.js +27 -0
- package/cli/commands/bind.d.ts +4 -0
- package/cli/commands/bind.js +10 -7
- package/cli/commands/bootstrap.d.ts +13 -0
- package/cli/commands/bootstrap.js +11 -0
- package/cli/commands/build.d.ts +6 -2
- package/cli/commands/build.js +13 -8
- package/cli/commands/console.d.ts +5 -1
- package/cli/commands/console.js +8 -6
- package/cli/commands/deploy.d.ts +4 -2
- package/cli/commands/deploy.js +69 -29
- package/cli/commands/dev.d.ts +5 -1
- package/cli/commands/dev.js +157 -79
- package/cli/commands/diff.d.ts +15 -0
- package/cli/commands/diff.js +61 -0
- package/cli/commands/env.d.ts +5 -1
- package/cli/commands/env.js +14 -15
- package/cli/commands/plugins/kysely.js +13 -5
- package/cli/commands/plugins/pothos.js +9 -4
- package/cli/commands/remove.d.ts +4 -0
- package/cli/commands/remove.js +26 -18
- package/cli/commands/secrets/get.d.ts +7 -3
- package/cli/commands/secrets/get.js +11 -24
- package/cli/commands/secrets/list.d.ts +6 -2
- package/cli/commands/secrets/list.js +15 -7
- package/cli/commands/secrets/remove.d.ts +8 -4
- package/cli/commands/secrets/remove.js +18 -16
- package/cli/commands/secrets/secrets.js +3 -3
- package/cli/commands/secrets/set.d.ts +8 -6
- package/cli/commands/secrets/set.js +16 -33
- package/cli/commands/telemetry.d.ts +15 -0
- package/cli/commands/telemetry.js +17 -0
- package/cli/commands/transform.d.ts +15 -0
- package/cli/commands/transform.js +55 -0
- package/cli/commands/update.d.ts +6 -2
- package/cli/commands/update.js +41 -33
- package/cli/commands/version.d.ts +13 -0
- package/cli/commands/version.js +7 -0
- package/cli/local/router.d.ts +6 -6
- package/cli/local/router.js +3 -3
- package/cli/local/server.d.ts +5 -3
- package/cli/local/server.js +21 -14
- package/cli/program.d.ts +5 -1
- package/cli/program.js +29 -5
- package/cli/spinner.js +2 -0
- package/cli/sst.js +35 -23
- package/cli/telemetry/environment.d.ts +1 -1
- package/cli/telemetry/environment.js +1 -1
- package/cli/terminal.d.ts +1 -0
- package/cli/terminal.js +8 -0
- package/cli/ui/deploy.d.ts +3 -2
- package/cli/ui/deploy.js +106 -106
- package/cli/ui/functions.d.ts +2 -0
- package/cli/ui/functions.js +132 -0
- package/cli/ui/header.d.ts +5 -0
- package/cli/ui/header.js +16 -0
- package/cli/ui/stack.d.ts +1 -0
- package/cli/ui/stack.js +6 -0
- package/config.d.ts +1 -1
- package/config.js +8 -8
- package/constructs/Api.d.ts +3 -71
- package/constructs/Api.js +3 -42
- package/constructs/ApiGatewayV1Api.d.ts +3 -3
- package/constructs/ApiGatewayV1Api.js +4 -3
- package/constructs/App.d.ts +2 -22
- package/constructs/App.js +12 -25
- package/constructs/AppSyncApi.d.ts +4 -5
- package/constructs/AppSyncApi.js +8 -5
- package/constructs/AstroSite.d.ts +2 -3
- package/constructs/AstroSite.js +43 -53
- package/constructs/Auth.js +27 -16
- package/constructs/BaseSite.d.ts +10 -10
- package/constructs/BaseSite.js +2 -2
- package/constructs/Cognito.js +28 -28
- package/constructs/EdgeFunction.d.ts +6 -4
- package/constructs/EdgeFunction.js +56 -59
- package/constructs/EventBus.js +1 -1
- package/constructs/Function.d.ts +4 -44
- package/constructs/Function.js +14 -50
- package/constructs/FunctionalStack.d.ts +2 -2
- package/constructs/Job.d.ts +23 -63
- package/constructs/Job.js +11 -32
- package/constructs/Metadata.d.ts +18 -20
- package/constructs/NextjsSite.d.ts +21 -5
- package/constructs/NextjsSite.js +67 -101
- package/constructs/Queue.js +10 -10
- package/constructs/RDS.d.ts +1 -1
- package/constructs/RDS.js +1 -1
- package/constructs/RemixSite.d.ts +0 -2
- package/constructs/RemixSite.js +20 -20
- package/constructs/Script.js +1 -1
- package/constructs/Secret.js +5 -3
- package/constructs/SolidStartSite.d.ts +2 -3
- package/constructs/SolidStartSite.js +42 -52
- package/constructs/SsrFunction.d.ts +22 -0
- package/constructs/SsrFunction.js +113 -0
- package/constructs/SsrSite.d.ts +104 -104
- package/constructs/SsrSite.js +196 -217
- package/constructs/Stack.d.ts +1 -20
- package/constructs/Stack.js +3 -65
- package/constructs/StaticSite.d.ts +33 -53
- package/constructs/StaticSite.js +92 -118
- package/constructs/Table.d.ts +1 -1
- package/constructs/Table.js +4 -4
- package/constructs/Topic.js +1 -1
- package/constructs/cdk/certificate-base.d.ts +18 -0
- package/constructs/cdk/certificate-base.js +26 -0
- package/constructs/cdk/dns-validated-certificate.d.ts +77 -0
- package/constructs/cdk/dns-validated-certificate.js +125 -0
- package/constructs/cdk/website-redirect.d.ts +53 -0
- package/constructs/cdk/website-redirect.js +77 -0
- package/constructs/deferred_task.d.ts +1 -1
- package/constructs/deprecated/NextjsSite.js +8 -6
- package/constructs/index.d.ts +0 -6
- package/constructs/index.js +0 -6
- package/constructs/util/apiGatewayV1AccessLog.d.ts +1 -1
- package/constructs/util/apiGatewayV2AccessLog.js +4 -4
- package/constructs/util/apiGatewayV2Domain.js +9 -2
- package/constructs/util/appSyncApiDomain.d.ts +1 -1
- package/constructs/util/appSyncApiDomain.js +9 -15
- package/constructs/util/duration.d.ts +1 -1
- package/constructs/util/functionBinding.js +1 -1
- package/constructs/util/permission.d.ts +3 -3
- package/constructs/util/permission.js +16 -18
- package/constructs/util/size.d.ts +1 -1
- package/constructs/util/warning.js +2 -2
- package/context/context.d.ts +2 -2
- package/context/context.js +4 -4
- package/context/handler.d.ts +1 -1
- package/credentials.d.ts +1 -1
- package/credentials.js +42 -6
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/iot.js +6 -2
- package/logger.js +3 -1
- package/node/api/index.d.ts +2 -3
- package/node/api/index.js +8 -2
- package/node/auth/adapter/adapter.d.ts +1 -1
- package/node/auth/adapter/facebook.js +1 -1
- package/node/auth/adapter/github.js +4 -4
- package/node/auth/adapter/google.d.ts +1 -1
- package/node/auth/adapter/google.js +2 -2
- package/node/auth/adapter/twitch.js +1 -1
- package/node/auth/session.d.ts +1 -1
- package/node/config/index.d.ts +2 -2
- package/node/config/index.js +3 -8
- package/node/job/index.d.ts +2 -2
- package/node/site/index.js +3 -5
- package/package.json +26 -21
- package/pothos.js +1 -0
- package/project.d.ts +47 -0
- package/{app.js → project.js} +60 -53
- package/runtime/handlers/dotnet.d.ts +1 -1
- package/runtime/handlers/dotnet.js +4 -4
- package/runtime/handlers/go.d.ts +1 -1
- package/runtime/handlers/go.js +3 -3
- package/runtime/handlers/java.d.ts +1 -1
- package/runtime/handlers/java.js +4 -4
- package/runtime/handlers/node.d.ts +1 -1
- package/runtime/handlers/node.js +60 -39
- package/runtime/handlers/python.d.ts +1 -1
- package/runtime/handlers/python.js +3 -3
- package/runtime/handlers.js +15 -12
- package/runtime/iot.js +3 -0
- package/runtime/runtime.d.ts +4 -0
- package/runtime/server.d.ts +3 -3
- package/runtime/server.js +11 -5
- package/runtime/workers.d.ts +4 -2
- package/runtime/workers.js +13 -3
- package/site-env.js +2 -1
- package/sst.mjs +6357 -20848
- package/stacks/app-metadata.d.ts +7 -0
- package/stacks/app-metadata.js +78 -0
- package/stacks/assembly.d.ts +1 -0
- package/stacks/assembly.js +4 -0
- package/stacks/build.d.ts +1 -1
- package/stacks/build.js +41 -48
- package/stacks/deploy.d.ts +1 -0
- package/stacks/deploy.js +128 -7
- package/stacks/diff.d.ts +8 -0
- package/stacks/diff.js +62 -0
- package/stacks/index.d.ts +3 -0
- package/stacks/index.js +3 -0
- package/stacks/metadata.d.ts +2 -0
- package/stacks/metadata.js +14 -12
- package/stacks/monitor.d.ts +8 -3
- package/stacks/monitor.js +38 -4
- package/stacks/remove.js +0 -4
- package/stacks/synth.d.ts +1 -0
- package/stacks/synth.js +27 -13
- package/support/base-site-archiver.mjs +1 -1
- package/support/bootstrap-metadata-function/index.mjs +68740 -0
- package/support/bridge/bridge.mjs +28 -28
- package/support/certificate-requestor/index.js +549 -0
- package/support/custom-resources/index.mjs +3824 -26567
- package/support/dotnet6-bootstrap/release/dotnet-bootstrap.deps.json +1 -1
- package/support/dotnet6-bootstrap/release/dotnet-bootstrap.runtimeconfig.json +1 -1
- package/support/edge-function/edge-lambda.mjs +2 -2
- package/support/job-invoker/index.mjs +26 -0
- package/support/nodejs-runtime/index.mjs +75 -72
- package/support/rds-migrator/index.mjs +22 -23
- package/support/remix-site-function/edge-server.js +1 -1
- package/support/script-function/index.mjs +30485 -0
- package/support/{edge-function-code-replacer → sls-nextjs-site-function-code-replacer}/lambda-code-updater.py +0 -0
- package/support/ssr-site-function-archiver.mjs +96 -0
- package/watcher.js +1 -1
- package/app.d.ts +0 -36
- 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/constructs/GraphQLApi.d.ts +0 -98
- package/constructs/GraphQLApi.js +0 -80
- package/constructs/ReactStaticSite.d.ts +0 -20
- package/constructs/ReactStaticSite.js +0 -54
- package/constructs/Script/cfn-response.d.ts +0 -19
- package/constructs/Script/cfn-response.js +0 -77
- package/constructs/Script/index.d.ts +0 -1
- package/constructs/Script/index.js +0 -78
- package/constructs/Script/outbound.d.ts +0 -10
- package/constructs/Script/outbound.js +0 -42
- package/constructs/Script/util.d.ts +0 -2
- package/constructs/Script/util.js +0 -11
- package/constructs/ViteStaticSite.d.ts +0 -32
- package/constructs/ViteStaticSite.js +0 -66
- package/support/astro-site-html-stub/index.html +0 -99
- package/support/base-site-archiver.cjs +0 -116
- package/support/nextjs-site-html-stub/index.html +0 -99
- package/support/remix-site-html-stub/index.html +0 -99
- package/support/solid-start-site-html-stub/index.html +0 -99
- package/support/static-site-stub/index.html +0 -90
package/constructs/BaseSite.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { IHostedZone } from "aws-cdk-lib/aws-route53";
|
|
2
|
+
import { ErrorResponse, DistributionProps, BehaviorOptions, IOrigin } from "aws-cdk-lib/aws-cloudfront";
|
|
3
|
+
import { ICertificate } from "aws-cdk-lib/aws-certificatemanager";
|
|
4
4
|
/**
|
|
5
5
|
* The customDomain for this website. SST supports domains that are hosted either on [Route 53](https://aws.amazon.com/route53/) or externally.
|
|
6
6
|
*
|
|
@@ -61,13 +61,13 @@ export interface BaseSiteDomainProps {
|
|
|
61
61
|
/**
|
|
62
62
|
* Import the underlying Route 53 hosted zone.
|
|
63
63
|
*/
|
|
64
|
-
hostedZone?:
|
|
64
|
+
hostedZone?: IHostedZone;
|
|
65
65
|
/**
|
|
66
66
|
* Import the certificate for the domain. By default, SST will create a certificate with the domain name. The certificate will be created in the `us-east-1`(N. Virginia) region as required by AWS CloudFront.
|
|
67
67
|
*
|
|
68
68
|
* Set this option if you have an existing certificate in the `us-east-1` region in AWS Certificate Manager you want to use.
|
|
69
69
|
*/
|
|
70
|
-
certificate?:
|
|
70
|
+
certificate?: ICertificate;
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
export interface BaseSiteEnvironmentOutputsInfo {
|
|
@@ -82,11 +82,11 @@ export interface BaseSiteReplaceProps {
|
|
|
82
82
|
search: string;
|
|
83
83
|
replace: string;
|
|
84
84
|
}
|
|
85
|
-
export declare function buildErrorResponsesForRedirectToIndex(indexPage: string):
|
|
86
|
-
export declare function buildErrorResponsesFor404ErrorPage(errorPage: string):
|
|
87
|
-
export interface BaseSiteCdkDistributionProps extends Omit<
|
|
88
|
-
defaultBehavior?: Omit<
|
|
89
|
-
origin?:
|
|
85
|
+
export declare function buildErrorResponsesForRedirectToIndex(indexPage: string): ErrorResponse[];
|
|
86
|
+
export declare function buildErrorResponsesFor404ErrorPage(errorPage: string): ErrorResponse[];
|
|
87
|
+
export interface BaseSiteCdkDistributionProps extends Omit<DistributionProps, "defaultBehavior"> {
|
|
88
|
+
defaultBehavior?: Omit<BehaviorOptions, "origin"> & {
|
|
89
|
+
origin?: IOrigin;
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
export declare function getBuildCmdEnvironment(siteEnvironment?: {
|
package/constructs/BaseSite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Token } from "aws-cdk-lib";
|
|
2
2
|
export function buildErrorResponsesForRedirectToIndex(indexPage) {
|
|
3
3
|
return [
|
|
4
4
|
{
|
|
@@ -35,7 +35,7 @@ export function getBuildCmdEnvironment(siteEnvironment) {
|
|
|
35
35
|
//
|
|
36
36
|
const buildCmdEnvironment = {};
|
|
37
37
|
Object.entries(siteEnvironment || {}).forEach(([key, value]) => {
|
|
38
|
-
buildCmdEnvironment[key] =
|
|
38
|
+
buildCmdEnvironment[key] = Token.isUnresolved(value)
|
|
39
39
|
? `{{ ${key} }}`
|
|
40
40
|
: value;
|
|
41
41
|
});
|
package/constructs/Cognito.js
CHANGED
|
@@ -2,9 +2,9 @@ import { Construct } from "constructs";
|
|
|
2
2
|
import * as iam from "aws-cdk-lib/aws-iam";
|
|
3
3
|
import * as cognito from "aws-cdk-lib/aws-cognito";
|
|
4
4
|
import { Stack } from "./Stack.js";
|
|
5
|
-
import { getFunctionRef, isCDKConstruct } from "./Construct.js";
|
|
6
|
-
import { Function as Fn } from "./Function.js";
|
|
7
|
-
import { attachPermissionsToRole, attachPermissionsToPolicy } from "./util/permission.js";
|
|
5
|
+
import { getFunctionRef, isCDKConstruct, } from "./Construct.js";
|
|
6
|
+
import { Function as Fn, } from "./Function.js";
|
|
7
|
+
import { attachPermissionsToRole, attachPermissionsToPolicy, } from "./util/permission.js";
|
|
8
8
|
const CognitoUserPoolTriggerOperationMapping = {
|
|
9
9
|
createAuthChallenge: cognito.UserPoolOperation.CREATE_AUTH_CHALLENGE,
|
|
10
10
|
customEmailSender: cognito.UserPoolOperation.CUSTOM_EMAIL_SENDER,
|
|
@@ -17,7 +17,7 @@ const CognitoUserPoolTriggerOperationMapping = {
|
|
|
17
17
|
preSignUp: cognito.UserPoolOperation.PRE_SIGN_UP,
|
|
18
18
|
preTokenGeneration: cognito.UserPoolOperation.PRE_TOKEN_GENERATION,
|
|
19
19
|
userMigration: cognito.UserPoolOperation.USER_MIGRATION,
|
|
20
|
-
verifyAuthChallengeResponse: cognito.UserPoolOperation.VERIFY_AUTH_CHALLENGE_RESPONSE
|
|
20
|
+
verifyAuthChallengeResponse: cognito.UserPoolOperation.VERIFY_AUTH_CHALLENGE_RESPONSE,
|
|
21
21
|
};
|
|
22
22
|
/////////////////////
|
|
23
23
|
// Construct
|
|
@@ -79,7 +79,7 @@ export class Cognito extends Construct {
|
|
|
79
79
|
return this.attachPermissionsForUsers(this.cdk.unauthRole, arg1, arg2);
|
|
80
80
|
}
|
|
81
81
|
bindForTriggers(constructs) {
|
|
82
|
-
Object.values(this.functions).forEach(fn => fn.bind(constructs));
|
|
82
|
+
Object.values(this.functions).forEach((fn) => fn.bind(constructs));
|
|
83
83
|
}
|
|
84
84
|
bindForTrigger(triggerKey, constructs) {
|
|
85
85
|
const fn = this.getFunction(triggerKey);
|
|
@@ -89,7 +89,7 @@ export class Cognito extends Construct {
|
|
|
89
89
|
fn.bind(constructs);
|
|
90
90
|
}
|
|
91
91
|
attachPermissionsForTriggers(permissions) {
|
|
92
|
-
Object.values(this.functions).forEach(fn => fn.attachPermissions(permissions));
|
|
92
|
+
Object.values(this.functions).forEach((fn) => fn.attachPermissions(permissions));
|
|
93
93
|
}
|
|
94
94
|
attachPermissionsForTrigger(triggerKey, permissions) {
|
|
95
95
|
const fn = this.getFunction(triggerKey);
|
|
@@ -109,9 +109,9 @@ export class Cognito extends Construct {
|
|
|
109
109
|
userPoolId: this.cdk.userPool.userPoolId,
|
|
110
110
|
triggers: Object.entries(this.functions).map(([name, fun]) => ({
|
|
111
111
|
name,
|
|
112
|
-
fn: getFunctionRef(fun)
|
|
113
|
-
}))
|
|
114
|
-
}
|
|
112
|
+
fn: getFunctionRef(fun),
|
|
113
|
+
})),
|
|
114
|
+
},
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
/** @internal */
|
|
@@ -169,7 +169,7 @@ export class Cognito extends Construct {
|
|
|
169
169
|
selfSignUpEnabled: true,
|
|
170
170
|
signInCaseSensitive: false,
|
|
171
171
|
signInAliases: this.buildSignInAliases(login),
|
|
172
|
-
...cognitoUserPoolProps
|
|
172
|
+
...cognitoUserPoolProps,
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
}
|
|
@@ -183,7 +183,7 @@ export class Cognito extends Construct {
|
|
|
183
183
|
{});
|
|
184
184
|
this.cdk.userPoolClient = new cognito.UserPoolClient(this, "UserPoolClient", {
|
|
185
185
|
userPool: this.cdk.userPool,
|
|
186
|
-
...clientProps
|
|
186
|
+
...clientProps,
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
189
|
}
|
|
@@ -203,7 +203,7 @@ export class Cognito extends Construct {
|
|
|
203
203
|
const urlSuffix = Stack.of(this).urlSuffix;
|
|
204
204
|
cognitoIdentityProviders.push({
|
|
205
205
|
providerName: `cognito-idp.${app.region}.${urlSuffix}/${this.cdk.userPool.userPoolId}`,
|
|
206
|
-
clientId: this.cdk.userPoolClient.userPoolClientId
|
|
206
|
+
clientId: this.cdk.userPoolClient.userPoolClientId,
|
|
207
207
|
});
|
|
208
208
|
if (typeof identityPoolFederation === "object") {
|
|
209
209
|
const { auth0, amazon, apple, facebook, google, twitter } = identityPoolFederation;
|
|
@@ -221,7 +221,7 @@ export class Cognito extends Construct {
|
|
|
221
221
|
url: auth0.domain.startsWith("https://")
|
|
222
222
|
? auth0.domain
|
|
223
223
|
: `https://${auth0.domain}`,
|
|
224
|
-
clientIds: [auth0.clientId]
|
|
224
|
+
clientIds: [auth0.clientId],
|
|
225
225
|
});
|
|
226
226
|
openIdConnectProviderArns.push(provider.openIdConnectProviderArn);
|
|
227
227
|
}
|
|
@@ -272,7 +272,7 @@ export class Cognito extends Construct {
|
|
|
272
272
|
cognitoIdentityProviders,
|
|
273
273
|
supportedLoginProviders,
|
|
274
274
|
openIdConnectProviderArns,
|
|
275
|
-
...identityPoolProps
|
|
275
|
+
...identityPoolProps,
|
|
276
276
|
});
|
|
277
277
|
this.cdk.authRole = this.createAuthRole(this.cdk.cfnIdentityPool);
|
|
278
278
|
this.cdk.unauthRole = this.createUnauthRole(this.cdk.cfnIdentityPool);
|
|
@@ -281,8 +281,8 @@ export class Cognito extends Construct {
|
|
|
281
281
|
identityPoolId: this.cdk.cfnIdentityPool.ref,
|
|
282
282
|
roles: {
|
|
283
283
|
authenticated: this.cdk.authRole.roleArn,
|
|
284
|
-
unauthenticated: this.cdk.unauthRole.roleArn
|
|
285
|
-
}
|
|
284
|
+
unauthenticated: this.cdk.unauthRole.roleArn,
|
|
285
|
+
},
|
|
286
286
|
});
|
|
287
287
|
}
|
|
288
288
|
addTriggers() {
|
|
@@ -315,21 +315,21 @@ export class Cognito extends Construct {
|
|
|
315
315
|
const role = new iam.Role(this, "IdentityPoolAuthRole", {
|
|
316
316
|
assumedBy: new iam.FederatedPrincipal("cognito-identity.amazonaws.com", {
|
|
317
317
|
StringEquals: {
|
|
318
|
-
"cognito-identity.amazonaws.com:aud": identityPool.ref
|
|
318
|
+
"cognito-identity.amazonaws.com:aud": identityPool.ref,
|
|
319
319
|
},
|
|
320
320
|
"ForAnyValue:StringLike": {
|
|
321
|
-
"cognito-identity.amazonaws.com:amr": "authenticated"
|
|
322
|
-
}
|
|
323
|
-
}, "sts:AssumeRoleWithWebIdentity")
|
|
321
|
+
"cognito-identity.amazonaws.com:amr": "authenticated",
|
|
322
|
+
},
|
|
323
|
+
}, "sts:AssumeRoleWithWebIdentity"),
|
|
324
324
|
});
|
|
325
325
|
role.addToPolicy(new iam.PolicyStatement({
|
|
326
326
|
effect: iam.Effect.ALLOW,
|
|
327
327
|
actions: [
|
|
328
328
|
"mobileanalytics:PutEvents",
|
|
329
329
|
"cognito-sync:*",
|
|
330
|
-
"cognito-identity:*"
|
|
330
|
+
"cognito-identity:*",
|
|
331
331
|
],
|
|
332
|
-
resources: ["*"]
|
|
332
|
+
resources: ["*"],
|
|
333
333
|
}));
|
|
334
334
|
return role;
|
|
335
335
|
}
|
|
@@ -337,17 +337,17 @@ export class Cognito extends Construct {
|
|
|
337
337
|
const role = new iam.Role(this, "IdentityPoolUnauthRole", {
|
|
338
338
|
assumedBy: new iam.FederatedPrincipal("cognito-identity.amazonaws.com", {
|
|
339
339
|
StringEquals: {
|
|
340
|
-
"cognito-identity.amazonaws.com:aud": identityPool.ref
|
|
340
|
+
"cognito-identity.amazonaws.com:aud": identityPool.ref,
|
|
341
341
|
},
|
|
342
342
|
"ForAnyValue:StringLike": {
|
|
343
|
-
"cognito-identity.amazonaws.com:amr": "unauthenticated"
|
|
344
|
-
}
|
|
345
|
-
}, "sts:AssumeRoleWithWebIdentity")
|
|
343
|
+
"cognito-identity.amazonaws.com:amr": "unauthenticated",
|
|
344
|
+
},
|
|
345
|
+
}, "sts:AssumeRoleWithWebIdentity"),
|
|
346
346
|
});
|
|
347
347
|
role.addToPolicy(new iam.PolicyStatement({
|
|
348
348
|
effect: iam.Effect.ALLOW,
|
|
349
349
|
actions: ["mobileanalytics:PutEvents", "cognito-sync:*"],
|
|
350
|
-
resources: ["*"]
|
|
350
|
+
resources: ["*"],
|
|
351
351
|
}));
|
|
352
352
|
return role;
|
|
353
353
|
}
|
|
@@ -359,7 +359,7 @@ export class Cognito extends Construct {
|
|
|
359
359
|
email: login.includes("email"),
|
|
360
360
|
phone: login.includes("phone"),
|
|
361
361
|
username: login.includes("username"),
|
|
362
|
-
preferredUsername: login.includes("preferredUsername")
|
|
362
|
+
preferredUsername: login.includes("preferredUsername"),
|
|
363
363
|
};
|
|
364
364
|
}
|
|
365
365
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Construct, IConstruct } from "constructs";
|
|
2
2
|
import * as iam from "aws-cdk-lib/aws-iam";
|
|
3
3
|
import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
4
|
+
import { Size } from "./util/size.js";
|
|
5
|
+
import { Duration } from "./util/duration.js";
|
|
4
6
|
import { Permissions } from "./util/permission.js";
|
|
5
7
|
export interface EdgeFunctionProps {
|
|
6
8
|
bundlePath: string;
|
|
7
9
|
handler: string;
|
|
8
|
-
timeout
|
|
9
|
-
|
|
10
|
+
timeout: number | Duration;
|
|
11
|
+
memorySize: number | Size;
|
|
10
12
|
permissions?: Permissions;
|
|
11
|
-
format
|
|
13
|
+
format: "cjs" | "esm";
|
|
12
14
|
environment?: Record<string, string>;
|
|
13
15
|
/**
|
|
14
16
|
* This is intended to be used internally by SST to make constructs
|
|
@@ -32,11 +34,11 @@ export declare class EdgeFunction extends Construct {
|
|
|
32
34
|
private createAsset;
|
|
33
35
|
private createRole;
|
|
34
36
|
private createFunction;
|
|
35
|
-
private createSingletonAwsCliLayer;
|
|
36
37
|
private createLambdaCodeReplacer;
|
|
37
38
|
private createSingletonBucketCR;
|
|
38
39
|
private createFunctionCR;
|
|
39
40
|
private createVersionCR;
|
|
41
|
+
private getLambdaContentReplaceValues;
|
|
40
42
|
private updateVersionLogicalId;
|
|
41
43
|
private trimFromStart;
|
|
42
44
|
private calculateHash;
|
|
@@ -6,9 +6,10 @@ import { Construct } from "constructs";
|
|
|
6
6
|
import * as iam from "aws-cdk-lib/aws-iam";
|
|
7
7
|
import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
8
8
|
import * as s3Assets from "aws-cdk-lib/aws-s3-assets";
|
|
9
|
-
import {
|
|
10
|
-
import { Lazy, Duration, CustomResource, } from "aws-cdk-lib";
|
|
9
|
+
import { Lazy, Duration as CdkDuration, CustomResource, } from "aws-cdk-lib";
|
|
11
10
|
import { Stack } from "./Stack.js";
|
|
11
|
+
import { toCdkSize } from "./util/size.js";
|
|
12
|
+
import { toCdkDuration } from "./util/duration.js";
|
|
12
13
|
import { attachPermissionsToRole } from "./util/permission.js";
|
|
13
14
|
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
14
15
|
/////////////////////
|
|
@@ -23,7 +24,7 @@ export class EdgeFunction extends Construct {
|
|
|
23
24
|
constructor(scope, id, props) {
|
|
24
25
|
super(scope, id);
|
|
25
26
|
this.props = props;
|
|
26
|
-
const {
|
|
27
|
+
const { scopeOverride } = props;
|
|
27
28
|
// Correct scope
|
|
28
29
|
this.scope = scopeOverride || this;
|
|
29
30
|
// Wrap function code
|
|
@@ -63,7 +64,7 @@ const handler = async (event) => {
|
|
|
63
64
|
// replacer to inject the environment variables assigned to the
|
|
64
65
|
// EdgeFunction construct.
|
|
65
66
|
//
|
|
66
|
-
// "{{
|
|
67
|
+
// "{{ _SST_FUNCTION_ENVIRONMENT_ }}" will get replaced during
|
|
67
68
|
// deployment with an object of environment key-value pairs, ie.
|
|
68
69
|
// const environment = {"API_URL": "https://api.example.com"};
|
|
69
70
|
//
|
|
@@ -71,7 +72,7 @@ const handler = async (event) => {
|
|
|
71
72
|
// support runtime environment variables. A downside of this approach
|
|
72
73
|
// is that environment variables cannot be toggled after deployment,
|
|
73
74
|
// each change to one requires a redeployment.
|
|
74
|
-
const environment = "{{
|
|
75
|
+
const environment = "{{ _SST_FUNCTION_ENVIRONMENT_ }}";
|
|
75
76
|
process.env = { ...process.env, ...environment };
|
|
76
77
|
} catch (e) {
|
|
77
78
|
console.log("Failed to set SST Lambda@Edge environment.");
|
|
@@ -97,7 +98,7 @@ ${exports}
|
|
|
97
98
|
const role = new iam.Role(this.scope, `ServerLambdaRole`, {
|
|
98
99
|
assumedBy: new iam.CompositePrincipal(new iam.ServicePrincipal("lambda.amazonaws.com"), new iam.ServicePrincipal("edgelambda.amazonaws.com")),
|
|
99
100
|
managedPolicies: [
|
|
100
|
-
iam.ManagedPolicy.fromManagedPolicyArn(this, "EdgeLambdaPolicy",
|
|
101
|
+
iam.ManagedPolicy.fromManagedPolicyArn(this, "EdgeLambdaPolicy", `arn:${Stack.of(this).partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole`),
|
|
101
102
|
],
|
|
102
103
|
});
|
|
103
104
|
// Attach permission
|
|
@@ -107,7 +108,7 @@ ${exports}
|
|
|
107
108
|
return role;
|
|
108
109
|
}
|
|
109
110
|
createFunction(asset) {
|
|
110
|
-
const { timeout,
|
|
111
|
+
const { timeout, memorySize } = this.props;
|
|
111
112
|
const name = this.node.id;
|
|
112
113
|
// Create a S3 bucket in us-east-1 to store Lambda code. Create
|
|
113
114
|
// 1 bucket for all Edge functions.
|
|
@@ -122,8 +123,12 @@ ${exports}
|
|
|
122
123
|
S3Key: asset.s3ObjectKey,
|
|
123
124
|
},
|
|
124
125
|
Runtime: lambda.Runtime.NODEJS_18_X.name,
|
|
125
|
-
MemorySize:
|
|
126
|
-
|
|
126
|
+
MemorySize: typeof memorySize === "string"
|
|
127
|
+
? toCdkSize(memorySize).toMebibytes()
|
|
128
|
+
: memorySize,
|
|
129
|
+
Timeout: typeof timeout === "string"
|
|
130
|
+
? toCdkDuration(timeout).toSeconds()
|
|
131
|
+
: timeout,
|
|
127
132
|
Role: this.role.roleArn,
|
|
128
133
|
});
|
|
129
134
|
const functionArn = functionCR.getAttString("FunctionArn");
|
|
@@ -132,63 +137,29 @@ ${exports}
|
|
|
132
137
|
const versionId = versionCR.getAttString("Version");
|
|
133
138
|
this.updateVersionLogicalId(functionCR, versionCR);
|
|
134
139
|
// Deploy after the code is updated
|
|
135
|
-
const updaterCR = this.createLambdaCodeReplacer(
|
|
140
|
+
const updaterCR = this.createLambdaCodeReplacer(asset);
|
|
136
141
|
functionCR.node.addDependency(updaterCR);
|
|
137
142
|
return { functionArn, versionId };
|
|
138
143
|
}
|
|
139
|
-
|
|
140
|
-
// Do not recreate if exist
|
|
141
|
-
const resId = "AwsCliLayer";
|
|
142
|
-
const stack = Stack.of(this);
|
|
143
|
-
const existingResource = stack.node.tryFindChild(resId);
|
|
144
|
-
if (existingResource) {
|
|
145
|
-
return existingResource;
|
|
146
|
-
}
|
|
147
|
-
// Create custom resource
|
|
148
|
-
return new AwsCliLayer(stack, resId);
|
|
149
|
-
}
|
|
150
|
-
createLambdaCodeReplacer(name, asset) {
|
|
144
|
+
createLambdaCodeReplacer(asset) {
|
|
151
145
|
// Note: Source code for the Lambda functions have "{{ ENV_KEY }}" in them.
|
|
152
146
|
// They need to be replaced with real values before the Lambda
|
|
153
147
|
// functions get deployed.
|
|
154
|
-
const { format } = this.props;
|
|
155
|
-
const providerId = "LambdaCodeReplacerProvider";
|
|
156
|
-
const resId = `${name}LambdaCodeReplacer`;
|
|
157
148
|
const stack = Stack.of(this);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
provider = new lambda.Function(stack, providerId, {
|
|
162
|
-
code: lambda.Code.fromAsset(path.join(__dirname, "../support/edge-function-code-replacer")),
|
|
163
|
-
layers: [this.createSingletonAwsCliLayer()],
|
|
164
|
-
runtime: lambda.Runtime.PYTHON_3_7,
|
|
165
|
-
handler: "lambda-code-updater.handler",
|
|
166
|
-
timeout: Duration.minutes(15),
|
|
167
|
-
memorySize: 1024,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
// Allow provider to perform search/replace on the asset
|
|
171
|
-
provider.role?.addToPrincipalPolicy(new iam.PolicyStatement({
|
|
172
|
-
effect: iam.Effect.ALLOW,
|
|
173
|
-
actions: ["s3:*"],
|
|
174
|
-
resources: [`arn:aws:s3:::${asset.s3BucketName}/${asset.s3ObjectKey}`],
|
|
175
|
-
}));
|
|
176
|
-
// Create custom resource to replace the code
|
|
177
|
-
const resource = new CustomResource(this.scope, resId, {
|
|
178
|
-
serviceToken: provider.functionArn,
|
|
179
|
-
resourceType: "Custom::SSTLambdaCodeUpdater",
|
|
149
|
+
const resource = new CustomResource(this.scope, "AssetReplacer", {
|
|
150
|
+
serviceToken: stack.customResourceHandler.functionArn,
|
|
151
|
+
resourceType: "Custom::AssetReplacer",
|
|
180
152
|
properties: {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
},
|
|
185
|
-
ReplaceValues: [{
|
|
186
|
-
files: `index-wrapper.${format === "esm" ? "mjs" : "cjs"}`,
|
|
187
|
-
search: '"{{ _SST_EDGE_FUNCTION_ENVIRONMENT_ }}"',
|
|
188
|
-
replace: JSON.stringify(this.props.environment || {}),
|
|
189
|
-
}],
|
|
153
|
+
bucket: asset.s3BucketName,
|
|
154
|
+
key: asset.s3ObjectKey,
|
|
155
|
+
replacements: this.getLambdaContentReplaceValues(),
|
|
190
156
|
},
|
|
191
157
|
});
|
|
158
|
+
stack.customResourceHandler.role?.addToPrincipalPolicy(new iam.PolicyStatement({
|
|
159
|
+
effect: iam.Effect.ALLOW,
|
|
160
|
+
actions: ["s3:GetObject", "s3:PutObject"],
|
|
161
|
+
resources: [`arn:${stack.partition}:s3:::${asset.s3BucketName}/*`],
|
|
162
|
+
}));
|
|
192
163
|
return resource;
|
|
193
164
|
}
|
|
194
165
|
createSingletonBucketCR() {
|
|
@@ -205,7 +176,7 @@ ${exports}
|
|
|
205
176
|
code: lambda.Code.fromAsset(path.join(__dirname, "../support/edge-function")),
|
|
206
177
|
handler: "s3-bucket.handler",
|
|
207
178
|
runtime: lambda.Runtime.NODEJS_16_X,
|
|
208
|
-
timeout:
|
|
179
|
+
timeout: CdkDuration.minutes(15),
|
|
209
180
|
memorySize: 1024,
|
|
210
181
|
initialPolicy: [
|
|
211
182
|
new iam.PolicyStatement({
|
|
@@ -237,7 +208,7 @@ ${exports}
|
|
|
237
208
|
code: lambda.Code.fromAsset(path.join(__dirname, "../support/edge-function")),
|
|
238
209
|
handler: "edge-lambda.handler",
|
|
239
210
|
runtime: lambda.Runtime.NODEJS_16_X,
|
|
240
|
-
timeout:
|
|
211
|
+
timeout: CdkDuration.minutes(15),
|
|
241
212
|
memorySize: 1024,
|
|
242
213
|
initialPolicy: [
|
|
243
214
|
new iam.PolicyStatement({
|
|
@@ -275,7 +246,7 @@ ${exports}
|
|
|
275
246
|
code: lambda.Code.fromAsset(path.join(__dirname, "../support/edge-function")),
|
|
276
247
|
handler: "edge-lambda-version.handler",
|
|
277
248
|
runtime: lambda.Runtime.NODEJS_16_X,
|
|
278
|
-
timeout:
|
|
249
|
+
timeout: CdkDuration.minutes(15),
|
|
279
250
|
memorySize: 1024,
|
|
280
251
|
initialPolicy: [
|
|
281
252
|
new iam.PolicyStatement({
|
|
@@ -298,6 +269,32 @@ ${exports}
|
|
|
298
269
|
/////////////////////
|
|
299
270
|
// Internal Functions
|
|
300
271
|
/////////////////////
|
|
272
|
+
getLambdaContentReplaceValues() {
|
|
273
|
+
const { format } = this.props;
|
|
274
|
+
const replaceValues = [];
|
|
275
|
+
Object.entries(this.props.environment || {}).forEach(([key, value]) => {
|
|
276
|
+
const token = `{{ ${key} }}`;
|
|
277
|
+
replaceValues.push({
|
|
278
|
+
files: "**/*.js",
|
|
279
|
+
search: token,
|
|
280
|
+
replace: value,
|
|
281
|
+
}, {
|
|
282
|
+
files: "**/*.cjs",
|
|
283
|
+
search: token,
|
|
284
|
+
replace: value,
|
|
285
|
+
}, {
|
|
286
|
+
files: "**/*.mjs",
|
|
287
|
+
search: token,
|
|
288
|
+
replace: value,
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
replaceValues.push({
|
|
292
|
+
files: `index-wrapper.${format === "esm" ? "mjs" : "cjs"}`,
|
|
293
|
+
search: '"{{ _SST_FUNCTION_ENVIRONMENT_ }}"',
|
|
294
|
+
replace: JSON.stringify(this.props.environment || {}),
|
|
295
|
+
});
|
|
296
|
+
return replaceValues;
|
|
297
|
+
}
|
|
301
298
|
updateVersionLogicalId(functionCR, versionCR) {
|
|
302
299
|
// Override the version's logical ID with a lazy string which includes the
|
|
303
300
|
// hash of the function itself, so a new version resource is created when
|
package/constructs/EventBus.js
CHANGED
|
@@ -183,7 +183,7 @@ export class EventBus extends Construct {
|
|
|
183
183
|
eventBusName: this.cdk.eventBus.eventBusName,
|
|
184
184
|
rules: Object.entries(this.targetsData).map(([ruleName, rule]) => ({
|
|
185
185
|
key: ruleName,
|
|
186
|
-
targets: Object.values(rule).map(getFunctionRef),
|
|
186
|
+
targets: Object.values(rule).map(getFunctionRef).filter(Boolean),
|
|
187
187
|
targetNames: Object.keys(rule),
|
|
188
188
|
})),
|
|
189
189
|
},
|
package/constructs/Function.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import * as cdk from "aws-cdk-lib";
|
|
|
4
4
|
import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
5
5
|
import * as logs from "aws-cdk-lib/aws-logs";
|
|
6
6
|
import { Stack } from "./Stack.js";
|
|
7
|
-
import { Secret, Parameter } from "./Config.js";
|
|
8
7
|
import { SSTConstruct } from "./Construct.js";
|
|
9
8
|
import { Size } from "./util/size.js";
|
|
10
9
|
import { Duration } from "./util/duration.js";
|
|
@@ -34,9 +33,9 @@ declare const supportedRuntimes: {
|
|
|
34
33
|
java11: cdk.aws_lambda.Runtime;
|
|
35
34
|
"go1.x": cdk.aws_lambda.Runtime;
|
|
36
35
|
};
|
|
37
|
-
export
|
|
38
|
-
export
|
|
39
|
-
export
|
|
36
|
+
export type Runtime = keyof typeof supportedRuntimes;
|
|
37
|
+
export type FunctionInlineDefinition = string | Function;
|
|
38
|
+
export type FunctionDefinition = string | Function | FunctionProps;
|
|
40
39
|
export interface FunctionUrlCorsProps extends functionUrlCors.CorsProps {
|
|
41
40
|
}
|
|
42
41
|
export interface FunctionHooks {
|
|
@@ -222,27 +221,6 @@ export interface FunctionProps extends Omit<lambda.FunctionOptions, "functionNam
|
|
|
222
221
|
* ```
|
|
223
222
|
*/
|
|
224
223
|
bind?: SSTConstruct[];
|
|
225
|
-
/**
|
|
226
|
-
* Configure environment variables for the function
|
|
227
|
-
*
|
|
228
|
-
* @deprecated The "config" prop is deprecated, and will be removed in SST v2. Pass Parameters and Secrets in through the "bind" prop. Read more about how to upgrade here — https://docs.serverless-stack.com/constructs/function
|
|
229
|
-
*
|
|
230
|
-
* @example
|
|
231
|
-
* ```js
|
|
232
|
-
* // Change
|
|
233
|
-
* new Function(stack, "Function", {
|
|
234
|
-
* handler: "src/function.handler",
|
|
235
|
-
* config: [STRIPE_KEY, API_URL]
|
|
236
|
-
* })
|
|
237
|
-
*
|
|
238
|
-
* // To
|
|
239
|
-
* new Function(stack, "Function", {
|
|
240
|
-
* handler: "src/function.handler",
|
|
241
|
-
* bind: [STRIPE_KEY, API_URL]
|
|
242
|
-
* })
|
|
243
|
-
* ```
|
|
244
|
-
*/
|
|
245
|
-
config?: (Secret | Parameter)[];
|
|
246
224
|
/**
|
|
247
225
|
* Attaches the given list of permissions to the function. Configuring this property is equivalent to calling `attachPermissions()` after the function is created.
|
|
248
226
|
*
|
|
@@ -505,7 +483,7 @@ export interface JavaProps {
|
|
|
505
483
|
*/
|
|
506
484
|
experimentalUseProvidedRuntime?: "provided" | "provided.al2";
|
|
507
485
|
}
|
|
508
|
-
export
|
|
486
|
+
export type FunctionBundleProp = FunctionBundlePythonProps | boolean;
|
|
509
487
|
interface FunctionBundleBase {
|
|
510
488
|
}
|
|
511
489
|
/**
|
|
@@ -589,23 +567,6 @@ export declare class Function extends lambda.Function implements SSTConstruct {
|
|
|
589
567
|
* ```
|
|
590
568
|
*/
|
|
591
569
|
bind(constructs: SSTConstruct[]): void;
|
|
592
|
-
/**
|
|
593
|
-
* Attaches additional configs to function.
|
|
594
|
-
*
|
|
595
|
-
* @deprecated The "config" prop is deprecated, and will be removed in SST v2. Pass Parameters and Secrets in through the "bind" prop. Read more about how to upgrade here — https://docs.serverless-stack.com/constructs/function
|
|
596
|
-
*
|
|
597
|
-
* @example
|
|
598
|
-
* ```js
|
|
599
|
-
* const STRIPE_KEY = new Config.Secret(stack, "STRIPE_KEY");
|
|
600
|
-
*
|
|
601
|
-
* // Change
|
|
602
|
-
* job.addConfig([STRIPE_KEY]);
|
|
603
|
-
*
|
|
604
|
-
* // To
|
|
605
|
-
* job.bind([STRIPE_KEY]);
|
|
606
|
-
* ```
|
|
607
|
-
*/
|
|
608
|
-
addConfig(config: (Secret | Parameter)[]): void;
|
|
609
570
|
/**
|
|
610
571
|
* Attaches additional permissions to function.
|
|
611
572
|
*
|
|
@@ -642,7 +603,6 @@ export declare class Function extends lambda.Function implements SSTConstruct {
|
|
|
642
603
|
static normalizeMemorySize(memorySize?: number | Size): number;
|
|
643
604
|
static normalizeDiskSize(diskSize?: number | Size): cdk.Size;
|
|
644
605
|
static normalizeTimeout(timeout?: number | Duration): cdk.Duration;
|
|
645
|
-
static normalizeRuntime(runtime?: Runtime): Runtime;
|
|
646
606
|
static normalizeSrcPath(srcPath: string): string;
|
|
647
607
|
static handleImportedLayer(scope: Construct, layer: lambda.ILayerVersion): lambda.ILayerVersion;
|
|
648
608
|
static isInlineDefinition(definition: any): definition is FunctionInlineDefinition;
|