sst 1.16.0 → 2.0.0-rc.0
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/LICENSE +21 -0
- package/{dist/app.d.ts → app.d.ts} +8 -1
- package/app.js +122 -0
- package/{dist/bootstrap.d.ts → bootstrap.d.ts} +1 -0
- package/bootstrap.js +79 -0
- package/{dist/bus.d.ts → bus.d.ts} +0 -0
- package/{dist/bus.js → bus.js} +0 -0
- package/{dist/cache.d.ts → cache.d.ts} +0 -0
- package/{dist/cache.js → cache.js} +0 -0
- package/{dist/cdk → cdk}/cloudformation-deployments.d.ts +1 -1
- package/{dist/cdk → cdk}/cloudformation-deployments.js +1 -0
- package/{dist/cdk → cdk}/deploy-stack.d.ts +0 -0
- package/{dist/cdk → cdk}/deploy-stack.js +13 -6
- package/{dist/cli → cli}/commands/bind.d.ts +3 -1
- package/{dist/cli → cli}/commands/bind.js +8 -4
- package/{dist/cli → cli}/commands/build.d.ts +2 -0
- package/cli/commands/build.js +12 -0
- package/cli/commands/console.d.ts +9 -0
- package/cli/commands/console.js +15 -0
- package/{dist/cli → cli}/commands/deploy.d.ts +7 -1
- package/cli/commands/deploy.js +48 -0
- package/cli/commands/dev.d.ts +11 -0
- package/cli/commands/dev.js +188 -0
- package/cli/commands/env.d.ts +11 -0
- package/cli/commands/env.js +39 -0
- package/cli/commands/plugins/kysely.d.ts +1 -0
- package/cli/commands/plugins/kysely.js +91 -0
- package/cli/commands/plugins/pothos.d.ts +1 -0
- package/cli/commands/plugins/pothos.js +52 -0
- package/cli/commands/plugins/warmer.d.ts +1 -0
- package/cli/commands/plugins/warmer.js +33 -0
- package/cli/commands/remove.d.ts +13 -0
- package/cli/commands/remove.js +39 -0
- package/{dist/cli → cli}/commands/secrets/get.d.ts +2 -0
- package/{dist/cli → cli}/commands/secrets/get.js +0 -0
- package/{dist/cli → cli}/commands/secrets/list.d.ts +2 -0
- package/{dist/cli → cli}/commands/secrets/list.js +5 -5
- package/{dist/cli → cli}/commands/secrets/remove.d.ts +2 -0
- package/{dist/cli → cli}/commands/secrets/remove.js +0 -0
- package/{dist/cli → cli}/commands/secrets/secrets.d.ts +0 -0
- package/{dist/cli → cli}/commands/secrets/secrets.js +0 -0
- package/{dist/cli → cli}/commands/secrets/set.d.ts +2 -0
- package/{dist/cli → cli}/commands/secrets/set.js +13 -11
- package/{dist/cli → cli}/commands/update.d.ts +2 -0
- package/{dist/cli → cli}/commands/update.js +17 -21
- package/cli/local/router.d.ts +42 -0
- package/cli/local/router.js +43 -0
- package/cli/local/server.d.ts +20 -0
- package/cli/local/server.js +212 -0
- package/cli/program.d.ts +9 -0
- package/{dist/cli → cli}/program.js +6 -1
- package/{dist/cli → cli}/spinner.d.ts +0 -0
- package/{dist/cli → cli}/spinner.js +0 -0
- package/cli/sst.d.ts +2 -0
- package/{dist/cli → cli}/sst.js +27 -16
- package/cli/telemetry/environment.d.ts +15 -0
- package/cli/telemetry/environment.js +27 -0
- package/cli/telemetry/post-payload.d.ts +1 -0
- package/cli/telemetry/post-payload.js +18 -0
- package/cli/telemetry/project-id.d.ts +2 -0
- package/cli/telemetry/project-id.js +47 -0
- package/cli/telemetry/telemetry.d.ts +4 -0
- package/cli/telemetry/telemetry.js +90 -0
- package/cli/ui/deploy.d.ts +8 -0
- package/{dist/cli → cli}/ui/deploy.js +39 -1
- package/{dist/config.d.ts → config.d.ts} +0 -0
- package/{dist/config.js → config.js} +16 -4
- package/{dist/constructs → constructs}/Api.d.ts +98 -12
- package/{dist/constructs → constructs}/Api.js +93 -7
- package/{dist/constructs → constructs}/ApiGatewayV1Api.d.ts +0 -0
- package/{dist/constructs → constructs}/ApiGatewayV1Api.js +10 -5
- package/{dist/constructs → constructs}/App.d.ts +4 -26
- package/{dist/constructs → constructs}/App.js +119 -99
- package/{dist/constructs → constructs}/AppSyncApi.d.ts +3 -3
- package/{dist/constructs → constructs}/AppSyncApi.js +27 -20
- package/constructs/AstroSite.d.ts +25 -0
- package/constructs/AstroSite.js +111 -0
- package/constructs/AstroSite.tsdoc.d.ts +2 -0
- package/constructs/AstroSite.tsdoc.js +2 -0
- package/{dist/constructs → constructs}/Auth.d.ts +1 -1
- package/{dist/constructs → constructs}/Auth.js +6 -4
- package/{dist/constructs → constructs}/BaseSite.d.ts +0 -0
- package/{dist/constructs → constructs}/BaseSite.js +0 -0
- package/{dist/constructs → constructs}/Bucket.d.ts +0 -0
- package/{dist/constructs → constructs}/Bucket.js +6 -3
- package/{dist/constructs → constructs}/Cognito.d.ts +0 -0
- package/{dist/constructs → constructs}/Cognito.js +4 -1
- package/{dist/constructs → constructs}/Config.d.ts +0 -0
- package/{dist/constructs → constructs}/Config.js +0 -0
- package/{dist/constructs → constructs}/Construct.d.ts +0 -0
- package/{dist/constructs → constructs}/Construct.js +0 -0
- package/{dist/constructs → constructs}/Cron.d.ts +0 -0
- package/{dist/constructs → constructs}/Cron.js +7 -0
- package/{dist/constructs → constructs}/DebugApp.d.ts +2 -2
- package/{dist/constructs → constructs}/DebugApp.js +16 -0
- package/{dist/constructs → constructs}/DebugStack.d.ts +0 -0
- package/{dist/constructs → constructs}/DebugStack.js +4 -0
- package/{dist/constructs → constructs}/EdgeFunction.d.ts +1 -0
- package/{dist/constructs → constructs}/EdgeFunction.js +27 -22
- package/{dist/constructs → constructs}/EventBus.d.ts +0 -0
- package/{dist/constructs → constructs}/EventBus.js +7 -4
- package/{dist/constructs → constructs}/Function.d.ts +73 -174
- package/{dist/constructs → constructs}/Function.js +43 -83
- package/{dist/constructs → constructs}/FunctionalStack.d.ts +0 -0
- package/{dist/constructs → constructs}/FunctionalStack.js +5 -5
- package/{dist/constructs → constructs}/GraphQLApi.d.ts +11 -1
- package/{dist/constructs → constructs}/GraphQLApi.js +3 -0
- package/{dist/constructs → constructs}/Job.d.ts +0 -14
- package/{dist/constructs → constructs}/Job.js +50 -46
- package/{dist/constructs → constructs}/KinesisStream.d.ts +0 -0
- package/{dist/constructs → constructs}/KinesisStream.js +6 -3
- package/{dist/constructs → constructs}/Metadata.d.ts +1 -1
- package/{dist/constructs → constructs}/Metadata.js +0 -0
- package/constructs/NextjsSite.d.ts +33 -0
- package/constructs/NextjsSite.js +285 -0
- package/{dist/constructs → constructs}/Parameter.d.ts +0 -0
- package/{dist/constructs → constructs}/Parameter.js +3 -0
- package/{dist/constructs → constructs}/Queue.d.ts +0 -0
- package/{dist/constructs → constructs}/Queue.js +19 -12
- package/{dist/constructs → constructs}/RDS.d.ts +0 -0
- package/{dist/constructs → constructs}/RDS.js +26 -19
- package/{dist/constructs → constructs}/ReactStaticSite.d.ts +0 -0
- package/{dist/constructs → constructs}/ReactStaticSite.js +1 -1
- package/constructs/RemixSite.d.ts +28 -0
- package/constructs/RemixSite.js +150 -0
- package/constructs/RemixSite.tsdoc.d.ts +2 -0
- package/constructs/RemixSite.tsdoc.js +2 -0
- package/{dist/constructs → constructs}/Script/cfn-response.d.ts +0 -0
- package/{dist/constructs → constructs}/Script/cfn-response.js +0 -0
- package/{dist/constructs → constructs}/Script/index.d.ts +0 -0
- package/{dist/constructs → constructs}/Script/index.js +0 -0
- package/{dist/constructs → constructs}/Script/outbound.d.ts +1 -1
- package/{dist/constructs → constructs}/Script/outbound.js +0 -0
- package/{dist/constructs → constructs}/Script/util.d.ts +0 -0
- package/{dist/constructs → constructs}/Script/util.js +0 -0
- package/{dist/constructs → constructs}/Script.d.ts +0 -0
- package/{dist/constructs → constructs}/Script.js +13 -0
- package/{dist/constructs → constructs}/Secret.d.ts +0 -0
- package/{dist/constructs → constructs}/Secret.js +2 -0
- package/constructs/SolidStartSite.d.ts +24 -0
- package/constructs/SolidStartSite.js +103 -0
- package/constructs/SolidStartSite.tsdoc.d.ts +2 -0
- package/constructs/SolidStartSite.tsdoc.js +2 -0
- package/{dist/constructs/RemixSite.d.ts → constructs/SsrSite.d.ts} +69 -107
- package/{dist/constructs/RemixSite.js → constructs/SsrSite.js} +243 -446
- package/{dist/constructs → constructs}/Stack.d.ts +1 -1
- package/{dist/constructs → constructs}/Stack.js +19 -4
- package/{dist/constructs → constructs}/StaticSite.d.ts +44 -17
- package/{dist/constructs → constructs}/StaticSite.js +121 -72
- package/{dist/constructs → constructs}/Table.d.ts +0 -0
- package/{dist/constructs → constructs}/Table.js +9 -3
- package/{dist/constructs → constructs}/Topic.d.ts +0 -0
- package/{dist/constructs → constructs}/Topic.js +6 -3
- package/{dist/constructs → constructs}/ViteStaticSite.d.ts +0 -0
- package/{dist/constructs → constructs}/ViteStaticSite.js +2 -2
- package/{dist/constructs → constructs}/WebSocketApi.d.ts +0 -0
- package/{dist/constructs → constructs}/WebSocketApi.js +9 -4
- package/{dist/constructs → constructs}/context.d.ts +1 -1
- package/{dist/constructs → constructs}/context.js +0 -0
- package/{dist/constructs → constructs}/deferred_task.d.ts +0 -0
- package/{dist/constructs → constructs}/deferred_task.js +4 -2
- package/{dist/constructs → constructs/deprecated}/NextjsSite.d.ts +12 -8
- package/{dist/constructs → constructs/deprecated}/NextjsSite.js +112 -89
- package/{dist/constructs/nextjs-site → constructs/deprecated}/cross-region-helper.d.ts +0 -0
- package/{dist/constructs/nextjs-site → constructs/deprecated}/cross-region-helper.js +3 -3
- package/constructs/deprecated/index.d.ts +1 -0
- package/constructs/deprecated/index.js +1 -0
- package/{dist/constructs → constructs}/index.d.ts +3 -2
- package/{dist/constructs → constructs}/index.js +2 -0
- package/{dist/constructs → constructs}/util/apiGatewayV1AccessLog.d.ts +0 -0
- package/{dist/constructs → constructs}/util/apiGatewayV1AccessLog.js +0 -0
- package/{dist/constructs → constructs}/util/apiGatewayV2AccessLog.d.ts +0 -0
- package/{dist/constructs → constructs}/util/apiGatewayV2AccessLog.js +4 -4
- package/{dist/constructs → constructs}/util/apiGatewayV2Cors.d.ts +0 -0
- package/{dist/constructs → constructs}/util/apiGatewayV2Cors.js +0 -0
- package/{dist/constructs → constructs}/util/apiGatewayV2Domain.d.ts +0 -0
- package/{dist/constructs → constructs}/util/apiGatewayV2Domain.js +0 -0
- package/{dist/constructs → constructs}/util/appSyncApiDomain.d.ts +1 -1
- package/{dist/constructs → constructs}/util/appSyncApiDomain.js +15 -9
- package/{dist/constructs → constructs}/util/builder.d.ts +0 -0
- package/{dist/constructs → constructs}/util/builder.js +0 -0
- package/{dist/constructs → constructs}/util/duration.d.ts +0 -0
- package/{dist/constructs → constructs}/util/duration.js +0 -0
- package/{dist/constructs → constructs}/util/functionBinding.d.ts +0 -0
- package/{dist/constructs → constructs}/util/functionBinding.js +0 -0
- package/{dist/constructs → constructs}/util/functionUrlCors.d.ts +0 -0
- package/{dist/constructs → constructs}/util/functionUrlCors.js +0 -0
- package/{dist/constructs → constructs}/util/permission.d.ts +0 -0
- package/{dist/constructs → constructs}/util/permission.js +32 -16
- package/{dist/constructs → constructs}/util/python/bundling.d.ts +0 -0
- package/{dist/constructs → constructs}/util/python/bundling.js +0 -0
- package/{dist/constructs → constructs}/util/size.d.ts +0 -0
- package/{dist/constructs → constructs}/util/size.js +0 -0
- package/{dist/constructs → constructs}/util/warning.d.ts +0 -0
- package/{dist/constructs → constructs}/util/warning.js +0 -0
- package/{dist/context → context}/context.d.ts +1 -1
- package/{dist/context → context}/context.js +3 -4
- package/{dist/context → context}/handler.d.ts +0 -0
- package/{dist/context → context}/handler.js +1 -1
- package/{dist/context → context}/index.d.ts +0 -0
- package/{dist/context → context}/index.js +0 -0
- package/{dist/credentials.d.ts → credentials.d.ts} +3 -1
- package/{dist/credentials.js → credentials.js} +11 -3
- package/{dist/error.d.ts → error.d.ts} +0 -0
- package/{dist/error.js → error.js} +0 -0
- package/{dist/iot.d.ts → iot.d.ts} +0 -0
- package/{dist/iot.js → iot.js} +3 -0
- package/logger.d.ts +3 -0
- package/{dist/logger.js → logger.js} +12 -8
- package/node/api/index.d.ts +42 -0
- package/node/api/index.js +88 -0
- package/node/auth/adapter/adapter.d.ts +3 -0
- package/node/auth/adapter/adapter.js +3 -0
- package/node/auth/adapter/facebook.d.ts +2 -0
- package/node/auth/adapter/facebook.js +26 -0
- package/node/auth/adapter/github.d.ts +2 -0
- package/node/auth/adapter/github.js +21 -0
- package/node/auth/adapter/google.d.ts +9 -0
- package/node/auth/adapter/google.js +18 -0
- package/node/auth/adapter/link.d.ts +8 -0
- package/node/auth/adapter/link.js +39 -0
- package/node/auth/adapter/oauth.d.ts +25 -0
- package/node/auth/adapter/oauth.js +52 -0
- package/node/auth/adapter/oidc.d.ts +17 -0
- package/node/auth/adapter/oidc.js +50 -0
- package/node/auth/adapter/twitch.d.ts +2 -0
- package/node/auth/adapter/twitch.js +11 -0
- package/node/auth/auth.d.ts +24 -0
- package/node/auth/auth.js +118 -0
- package/node/auth/index.d.ts +10 -0
- package/node/auth/index.js +10 -0
- package/node/auth/session.d.ts +76 -0
- package/node/auth/session.js +109 -0
- package/node/bucket/index.d.ts +3 -0
- package/node/bucket/index.js +3 -0
- package/node/config/index.d.ts +13 -0
- package/node/config/index.js +88 -0
- package/node/event-bus/index.d.ts +3 -0
- package/node/event-bus/index.js +3 -0
- package/node/function/index.d.ts +3 -0
- package/node/function/index.js +3 -0
- package/node/graphql/index.d.ts +38 -0
- package/node/graphql/index.js +48 -0
- package/node/job/index.d.ts +34 -0
- package/node/job/index.js +51 -0
- package/node/kinesis-stream/index.d.ts +3 -0
- package/node/kinesis-stream/index.js +3 -0
- package/node/queue/index.d.ts +3 -0
- package/node/queue/index.js +3 -0
- package/node/rds/index.d.ts +3 -0
- package/node/rds/index.js +3 -0
- package/node/site/index.d.ts +15 -0
- package/node/site/index.js +64 -0
- package/node/table/index.d.ts +3 -0
- package/node/table/index.js +3 -0
- package/node/topic/index.d.ts +3 -0
- package/node/topic/index.js +3 -0
- package/node/util/index.d.ts +7 -0
- package/node/util/index.js +57 -0
- package/package.json +107 -40
- package/pothos.d.ts +8 -0
- package/pothos.js +156 -0
- package/runtime/handlers/dotnet.d.ts +1 -0
- package/runtime/handlers/dotnet.js +117 -0
- package/runtime/handlers/go.d.ts +1 -0
- package/runtime/handlers/go.js +105 -0
- package/runtime/handlers/java.d.ts +1 -0
- package/runtime/handlers/java.js +97 -0
- package/{dist/runtime → runtime/handlers}/node.d.ts +0 -0
- package/runtime/handlers/node.js +172 -0
- package/runtime/handlers/python.d.ts +1 -0
- package/runtime/handlers/python.js +89 -0
- package/{dist/runtime → runtime}/handlers.d.ts +30 -12
- package/runtime/handlers.js +117 -0
- package/{dist/runtime → runtime}/iot.d.ts +0 -0
- package/{dist/runtime → runtime}/iot.js +1 -1
- package/{dist/runtime → runtime}/runtime.d.ts +2 -0
- package/{dist/runtime → runtime}/runtime.js +0 -0
- package/{dist/runtime → runtime}/server.d.ts +0 -0
- package/{dist/runtime → runtime}/server.js +39 -3
- package/{dist/runtime → runtime}/workers.d.ts +1 -0
- package/{dist/runtime → runtime}/workers.js +12 -4
- package/{dist/cli/sst.d.ts → scrap.d.ts} +0 -0
- package/scrap.js +58 -0
- package/site-env.d.ts +13 -0
- package/site-env.js +47 -0
- package/sst.mjs +21848 -0
- package/{dist/stacks → stacks}/build.d.ts +0 -0
- package/{dist/stacks → stacks}/build.js +18 -9
- package/stacks/deploy.d.ts +8 -0
- package/stacks/deploy.js +105 -0
- package/stacks/index.d.ts +7 -0
- package/stacks/index.js +7 -0
- package/stacks/metadata.d.ts +9 -0
- package/{dist/stacks → stacks}/metadata.js +2 -14
- package/stacks/monitor.d.ts +27 -0
- package/stacks/monitor.js +111 -0
- package/stacks/remove.d.ts +8 -0
- package/stacks/remove.js +80 -0
- package/stacks/synth.d.ts +10 -0
- package/stacks/synth.js +77 -0
- package/support/astro-site-html-stub/index.html +99 -0
- package/support/base-site-archiver.cjs +12 -11
- package/support/base-site-archiver.mjs +20 -0
- package/support/bridge/bridge.mjs +59 -0
- package/{dist/support → support}/custom-resources/index.mjs +44209 -42781
- package/support/dotnet31-bootstrap/Program.cs +17 -0
- package/support/dotnet31-bootstrap/dotnet-bootstrap.csproj +12 -0
- package/support/dotnet31-bootstrap/release/Amazon.Lambda.Core.dll +0 -0
- package/support/dotnet31-bootstrap/release/Amazon.Lambda.RuntimeSupport.dll +0 -0
- package/support/dotnet31-bootstrap/release/System.Runtime.CompilerServices.Unsafe.dll +0 -0
- package/support/dotnet31-bootstrap/release/System.Text.Encodings.Web.dll +0 -0
- package/support/dotnet31-bootstrap/release/System.Text.Json.dll +0 -0
- package/support/dotnet31-bootstrap/release/dotnet-bootstrap +0 -0
- package/support/dotnet31-bootstrap/release/dotnet-bootstrap.deps.json +230 -0
- package/support/dotnet31-bootstrap/release/dotnet-bootstrap.dll +0 -0
- package/support/dotnet31-bootstrap/release/dotnet-bootstrap.pdb +0 -0
- package/support/dotnet31-bootstrap/release/dotnet-bootstrap.runtimeconfig.json +9 -0
- package/support/dotnet6-bootstrap/Program.cs +17 -0
- package/support/dotnet6-bootstrap/dotnet-bootstrap.csproj +12 -0
- package/support/dotnet6-bootstrap/release/Amazon.Lambda.Core.dll +0 -0
- package/support/dotnet6-bootstrap/release/Amazon.Lambda.RuntimeSupport.dll +0 -0
- package/support/dotnet6-bootstrap/release/dotnet-bootstrap +0 -0
- package/support/dotnet6-bootstrap/release/dotnet-bootstrap.deps.json +59 -0
- package/support/dotnet6-bootstrap/release/dotnet-bootstrap.dll +0 -0
- package/support/dotnet6-bootstrap/release/dotnet-bootstrap.pdb +0 -0
- package/support/dotnet6-bootstrap/release/dotnet-bootstrap.runtimeconfig.json +12 -0
- package/support/edge-function/edge-lambda-version.mjs +3 -0
- package/support/edge-function/edge-lambda.mjs +3 -0
- package/support/edge-function/s3-bucket.mjs +3 -0
- package/{dist/support/base-site-custom-resource/cf-invalidate.py → support/edge-function-code-replacer/lambda-code-updater.py} +56 -30
- package/support/java-runtime/install.sh +25 -0
- package/support/java-runtime/pom.xml +39 -0
- package/support/java-runtime/release/aws-lambda-java-core-1.2.0.jar +0 -0
- package/support/java-runtime/release/aws-lambda-java-runtime-interface-client-1.1.0.jar +0 -0
- package/support/java-runtime/release/aws-lambda-java-serialization-1.0.0.jar +0 -0
- package/support/nextjs-site-html-stub/index.html +99 -0
- package/{dist/support → support}/nodejs-runtime/index.mjs +7822 -2771
- package/support/python-runtime/runtime.py +116 -0
- package/support/rds-migrator/index.mjs +28 -0
- package/support/remix-site-function/edge-server.js +158 -0
- package/support/remix-site-function/polyfill.js +24 -0
- package/support/remix-site-function/regional-server.js +162 -0
- package/support/remix-site-html-stub/index.html +99 -0
- package/support/sls-nextjs-site-build-helper/build.cjs +91 -0
- package/support/sls-nextjs-site-build-helper/index-wrapper.js +19 -0
- package/support/sls-nextjs-site-stub/index.html +99 -0
- package/support/solid-start-site-html-stub/index.html +99 -0
- package/support/ssr-site-function-stub/index.js +5 -0
- package/util/fs.d.ts +4 -0
- package/util/fs.js +46 -0
- package/util/module.d.ts +1 -0
- package/util/module.js +5 -0
- package/util/process.d.ts +2 -0
- package/util/process.js +3 -0
- package/{dist/watcher.d.ts → watcher.d.ts} +0 -0
- package/{dist/watcher.js → watcher.js} +1 -1
- package/.build/sst-debug.log +0 -10
- package/.turbo/turbo-build.log +0 -2
- package/CHANGELOG.md +0 -332
- package/analyze +0 -11090
- package/bin/sst.mjs +0 -3
- package/build.mjs +0 -116
- package/debug.log +0 -6
- package/dist/app.js +0 -92
- package/dist/bootstrap.js +0 -23
- package/dist/cli/commands/build.js +0 -8
- package/dist/cli/commands/deploy.js +0 -20
- package/dist/cli/commands/env.d.ts +0 -0
- package/dist/cli/commands/env.js +0 -1
- package/dist/cli/commands/scrap.d.ts +0 -5
- package/dist/cli/commands/scrap.js +0 -1
- package/dist/cli/commands/start.d.ts +0 -7
- package/dist/cli/commands/start.js +0 -136
- package/dist/cli/program.d.ts +0 -7
- package/dist/cli/ui/deploy.d.ts +0 -6
- package/dist/constructs/nextjs-site/custom-resource/cfn-response.d.ts +0 -19
- package/dist/constructs/nextjs-site/custom-resource/cfn-response.js +0 -94
- package/dist/constructs/nextjs-site/custom-resource/edge-lambda-version.d.ts +0 -1
- package/dist/constructs/nextjs-site/custom-resource/edge-lambda-version.js +0 -138
- package/dist/constructs/nextjs-site/custom-resource/edge-lambda.d.ts +0 -1
- package/dist/constructs/nextjs-site/custom-resource/edge-lambda.js +0 -136
- package/dist/constructs/nextjs-site/custom-resource/s3-bucket.d.ts +0 -1
- package/dist/constructs/nextjs-site/custom-resource/s3-bucket.js +0 -94
- package/dist/constructs/nextjs-site/custom-resource/util.d.ts +0 -1
- package/dist/constructs/nextjs-site/custom-resource/util.js +0 -4
- package/dist/logger.d.ts +0 -9
- package/dist/runtime/handlers.js +0 -72
- package/dist/runtime/node.js +0 -99
- package/dist/sst.mjs +0 -164202
- package/dist/stacks/deploy.d.ts +0 -33
- package/dist/stacks/deploy.js +0 -168
- package/dist/stacks/index.d.ts +0 -21
- package/dist/stacks/index.js +0 -57
- package/dist/stacks/metadata.d.ts +0 -9
- package/dist/support/base-site-archiver.cjs +0 -115
- package/dist/support/base-site-custom-resource/s3-handler.py +0 -195
- package/dist/support/base-site-custom-resource/s3-upload.py +0 -91
- package/dist/support/bridge/bridge.mjs +0 -86
- package/dist/support/static-site-stub/index.html +0 -90
- package/src/app.ts +0 -140
- package/src/bootstrap.ts +0 -28
- package/src/bus.ts +0 -81
- package/src/cache.ts +0 -34
- package/src/cdk/cloudformation-deployments.ts +0 -730
- package/src/cdk/deploy-stack.ts +0 -1030
- package/src/cli/commands/bind.ts +0 -31
- package/src/cli/commands/build.ts +0 -16
- package/src/cli/commands/deploy.ts +0 -34
- package/src/cli/commands/env.ts +0 -0
- package/src/cli/commands/scrap.ts +0 -5
- package/src/cli/commands/secrets/get.ts +0 -50
- package/src/cli/commands/secrets/list.ts +0 -66
- package/src/cli/commands/secrets/remove.ts +0 -36
- package/src/cli/commands/secrets/secrets.ts +0 -17
- package/src/cli/commands/secrets/set.ts +0 -59
- package/src/cli/commands/start.tsx +0 -162
- package/src/cli/commands/update.ts +0 -100
- package/src/cli/program.ts +0 -22
- package/src/cli/spinner.ts +0 -14
- package/src/cli/sst.ts +0 -50
- package/src/cli/ui/deploy.tsx +0 -139
- package/src/config.ts +0 -226
- package/src/constructs/Api.ts +0 -1448
- package/src/constructs/ApiGatewayV1Api.ts +0 -1481
- package/src/constructs/App.ts +0 -744
- package/src/constructs/AppSyncApi.ts +0 -1045
- package/src/constructs/Auth.ts +0 -252
- package/src/constructs/BaseSite.ts +0 -146
- package/src/constructs/Bucket.ts +0 -670
- package/src/constructs/Cognito.ts +0 -708
- package/src/constructs/Config.ts +0 -4
- package/src/constructs/Construct.ts +0 -77
- package/src/constructs/Cron.ts +0 -235
- package/src/constructs/DebugApp.ts +0 -97
- package/src/constructs/DebugStack.ts +0 -182
- package/src/constructs/EdgeFunction.ts +0 -460
- package/src/constructs/EventBus.ts +0 -651
- package/src/constructs/Function.ts +0 -1329
- package/src/constructs/FunctionalStack.ts +0 -90
- package/src/constructs/GraphQLApi.ts +0 -140
- package/src/constructs/Job.ts +0 -557
- package/src/constructs/KinesisStream.ts +0 -388
- package/src/constructs/Metadata.ts +0 -75
- package/src/constructs/NextjsSite.ts +0 -1498
- package/src/constructs/Parameter.ts +0 -72
- package/src/constructs/Queue.ts +0 -360
- package/src/constructs/RDS.ts +0 -578
- package/src/constructs/ReactStaticSite.ts +0 -66
- package/src/constructs/RemixSite.ts +0 -1397
- package/src/constructs/Script/cfn-response.ts +0 -116
- package/src/constructs/Script/index.ts +0 -103
- package/src/constructs/Script/outbound.ts +0 -59
- package/src/constructs/Script/package.json +0 -3
- package/src/constructs/Script/util.ts +0 -19
- package/src/constructs/Script.ts +0 -270
- package/src/constructs/Secret.ts +0 -66
- package/src/constructs/Stack.ts +0 -319
- package/src/constructs/StaticSite.ts +0 -995
- package/src/constructs/Table.ts +0 -844
- package/src/constructs/Topic.ts +0 -486
- package/src/constructs/ViteStaticSite.ts +0 -99
- package/src/constructs/WebSocketApi.ts +0 -687
- package/src/constructs/context.ts +0 -12
- package/src/constructs/deferred_task.ts +0 -53
- package/src/constructs/descs.d.ts +0 -1
- package/src/constructs/index.ts +0 -39
- package/src/constructs/nextjs-site/cross-region-helper.ts +0 -189
- package/src/constructs/nextjs-site/custom-resource/cfn-response.ts +0 -146
- package/src/constructs/nextjs-site/custom-resource/edge-lambda-version.ts +0 -162
- package/src/constructs/nextjs-site/custom-resource/edge-lambda.ts +0 -167
- package/src/constructs/nextjs-site/custom-resource/s3-bucket.ts +0 -112
- package/src/constructs/nextjs-site/custom-resource/util.ts +0 -11
- package/src/constructs/util/apiGatewayV1AccessLog.ts +0 -106
- package/src/constructs/util/apiGatewayV2AccessLog.ts +0 -139
- package/src/constructs/util/apiGatewayV2Cors.ts +0 -94
- package/src/constructs/util/apiGatewayV2Domain.ts +0 -312
- package/src/constructs/util/appSyncApiDomain.ts +0 -204
- package/src/constructs/util/builder.ts +0 -17
- package/src/constructs/util/duration.ts +0 -27
- package/src/constructs/util/functionBinding.ts +0 -102
- package/src/constructs/util/functionUrlCors.ts +0 -96
- package/src/constructs/util/permission.ts +0 -299
- package/src/constructs/util/python/bundling.ts +0 -174
- package/src/constructs/util/size.ts +0 -13
- package/src/constructs/util/warning.ts +0 -20
- package/src/context/context.ts +0 -79
- package/src/context/handler.ts +0 -53
- package/src/context/index.ts +0 -2
- package/src/credentials.ts +0 -103
- package/src/error.ts +0 -5
- package/src/iot.ts +0 -105
- package/src/logger.ts +0 -35
- package/src/runtime/handlers.ts +0 -121
- package/src/runtime/iot.ts +0 -16
- package/src/runtime/node.ts +0 -111
- package/src/runtime/runtime.ts +0 -27
- package/src/runtime/server.ts +0 -149
- package/src/runtime/workers.ts +0 -96
- package/src/stacks/build.ts +0 -69
- package/src/stacks/deploy.ts +0 -232
- package/src/stacks/index.ts +0 -73
- package/src/stacks/metadata.ts +0 -125
- package/src/watcher.ts +0 -47
- package/sst.config.mjs +0 -6
- package/support/bridge/bridge.ts +0 -136
- package/support/bridge/build.mjs +0 -18
- package/support/custom-resources/auth-keys.ts +0 -113
- package/support/custom-resources/build.mjs +0 -18
- package/support/custom-resources/cfn-response.ts +0 -151
- package/support/custom-resources/index.ts +0 -18
- package/support/custom-resources/secrets-migration.ts +0 -82
- package/support/custom-resources/stack-metadata.ts +0 -75
- package/support/custom-resources/util.ts +0 -44
- package/support/nodejs-runtime/index.ts +0 -69
- package/support/tsconfig.json +0 -11
- package/tsconfig.json +0 -13
- package/yarn-error.log +0 -75
|
@@ -1,1481 +0,0 @@
|
|
|
1
|
-
import { Construct } from "constructs";
|
|
2
|
-
import * as cdk from "aws-cdk-lib";
|
|
3
|
-
import * as logs from "aws-cdk-lib/aws-logs";
|
|
4
|
-
import * as route53 from "aws-cdk-lib/aws-route53";
|
|
5
|
-
import * as route53Targets from "aws-cdk-lib/aws-route53-targets";
|
|
6
|
-
import * as iam from "aws-cdk-lib/aws-iam";
|
|
7
|
-
import * as acm from "aws-cdk-lib/aws-certificatemanager";
|
|
8
|
-
import * as cognito from "aws-cdk-lib/aws-cognito";
|
|
9
|
-
import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
10
|
-
import * as apig from "aws-cdk-lib/aws-apigateway";
|
|
11
|
-
import * as apigV1AccessLog from "./util/apiGatewayV1AccessLog.js";
|
|
12
|
-
|
|
13
|
-
import { App } from "./App.js";
|
|
14
|
-
import { Stack } from "./Stack.js";
|
|
15
|
-
import { Bucket } from "./Bucket.js";
|
|
16
|
-
import { Duration, toCdkDuration } from "./util/duration.js";
|
|
17
|
-
import { getFunctionRef, SSTConstruct, isCDKConstruct } from "./Construct.js";
|
|
18
|
-
import {
|
|
19
|
-
Function as Fn,
|
|
20
|
-
FunctionProps,
|
|
21
|
-
FunctionInlineDefinition,
|
|
22
|
-
FunctionDefinition,
|
|
23
|
-
} from "./Function.js";
|
|
24
|
-
import { Permissions } from "./util/permission.js";
|
|
25
|
-
|
|
26
|
-
const allowedMethods = [
|
|
27
|
-
"ANY",
|
|
28
|
-
"GET",
|
|
29
|
-
"PUT",
|
|
30
|
-
"POST",
|
|
31
|
-
"HEAD",
|
|
32
|
-
"PATCH",
|
|
33
|
-
"DELETE",
|
|
34
|
-
"OPTIONS",
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
/////////////////////
|
|
38
|
-
// Interfaces
|
|
39
|
-
/////////////////////
|
|
40
|
-
|
|
41
|
-
export interface ApiGatewayV1ApiAccessLogProps
|
|
42
|
-
extends apigV1AccessLog.AccessLogProps { }
|
|
43
|
-
|
|
44
|
-
export interface ApiGatewayV1ApiProps<
|
|
45
|
-
Authorizers extends Record<string, ApiGatewayV1ApiAuthorizer> = Record<
|
|
46
|
-
string,
|
|
47
|
-
never
|
|
48
|
-
>,
|
|
49
|
-
AuthorizerKeys = keyof Authorizers
|
|
50
|
-
> {
|
|
51
|
-
/**
|
|
52
|
-
* Define the routes for the API. Can be a function, proxy to another API, or point to an ALB
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
*
|
|
56
|
-
* ```js
|
|
57
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
58
|
-
* "GET /notes" : "src/list.main",
|
|
59
|
-
* "GET /notes/{id}" : "src/get.main",
|
|
60
|
-
* "$default": "src/default.main"
|
|
61
|
-
* })
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
routes?: Record<string, ApiGatewayV1ApiRouteProps<AuthorizerKeys>>;
|
|
65
|
-
/**
|
|
66
|
-
* CORS support applied to all endpoints in this API
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
*
|
|
70
|
-
* ```js
|
|
71
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
72
|
-
* cors: true,
|
|
73
|
-
* });
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
*/
|
|
77
|
-
cors?: boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Enable CloudWatch access logs for this API
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```js
|
|
83
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
84
|
-
* accessLog: true
|
|
85
|
-
* });
|
|
86
|
-
*
|
|
87
|
-
* ```
|
|
88
|
-
* @example
|
|
89
|
-
* ```js
|
|
90
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
91
|
-
* accessLog: {
|
|
92
|
-
* retention: "one_week",
|
|
93
|
-
* },
|
|
94
|
-
* });
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
accessLog?: boolean | string | ApiGatewayV1ApiAccessLogProps;
|
|
98
|
-
/**
|
|
99
|
-
* Specify a custom domain to use in addition to the automatically generated one. SST currently supports domains that are configured using [Route 53](https://aws.amazon.com/route53/)
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```js
|
|
103
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
104
|
-
* customDomain: "api.example.com"
|
|
105
|
-
* })
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```js
|
|
110
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
111
|
-
* customDomain: {
|
|
112
|
-
* domainName: "api.example.com",
|
|
113
|
-
* hostedZone: "domain.com",
|
|
114
|
-
* path: "v1"
|
|
115
|
-
* }
|
|
116
|
-
* })
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
customDomain?: string | ApiGatewayV1ApiCustomDomainProps;
|
|
120
|
-
/**
|
|
121
|
-
* Define the authorizers for the API. Can be a user pool, JWT, or Lambda authorizers.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```js
|
|
125
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
126
|
-
* authorizers: {
|
|
127
|
-
* MyAuthorizer: {
|
|
128
|
-
* type: "user_pools",
|
|
129
|
-
* userPoolIds: [userPool.userPoolId],
|
|
130
|
-
* },
|
|
131
|
-
* },
|
|
132
|
-
* });
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
authorizers?: Authorizers;
|
|
136
|
-
defaults?: {
|
|
137
|
-
/**
|
|
138
|
-
* The default function props to be applied to all the Lambda functions in the API. The `environment`, `permissions` and `layers` properties will be merged with per route definitions if they are defined.
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```js
|
|
142
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
143
|
-
* defaults: {
|
|
144
|
-
* function: {
|
|
145
|
-
* timeout: 20,
|
|
146
|
-
* environment: { tableName: table.tableName },
|
|
147
|
-
* permissions: [table],
|
|
148
|
-
* }
|
|
149
|
-
* er
|
|
150
|
-
* });
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
function?: FunctionProps;
|
|
154
|
-
/**
|
|
155
|
-
* The authorizer for all the routes in the API.
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* ```js
|
|
159
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
160
|
-
* defaults: {
|
|
161
|
-
* authorizer: "iam",
|
|
162
|
-
* }
|
|
163
|
-
* });
|
|
164
|
-
* ```
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```js
|
|
168
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
169
|
-
* authorizers: {
|
|
170
|
-
* Authorizer: {
|
|
171
|
-
* type: "user_pools",
|
|
172
|
-
* userPoolIds: [userPool.userPoolId],
|
|
173
|
-
* },
|
|
174
|
-
* },
|
|
175
|
-
* defaults: {
|
|
176
|
-
* authorizer: "Authorizer",
|
|
177
|
-
* }
|
|
178
|
-
* });
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
authorizer?:
|
|
182
|
-
| "none"
|
|
183
|
-
| "iam"
|
|
184
|
-
| (string extends AuthorizerKeys ? never : AuthorizerKeys);
|
|
185
|
-
/**
|
|
186
|
-
* An array of scopes to include in the authorization when using `user_pool` or `jwt` authorizers. These will be merged with the scopes from the attached authorizer.
|
|
187
|
-
* @default []
|
|
188
|
-
*/
|
|
189
|
-
authorizationScopes?: string[];
|
|
190
|
-
};
|
|
191
|
-
cdk?: {
|
|
192
|
-
/**
|
|
193
|
-
* Allows you to override default id for this construct.
|
|
194
|
-
*/
|
|
195
|
-
id?: string;
|
|
196
|
-
/**
|
|
197
|
-
* Override the internally created rest api
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* ```js
|
|
201
|
-
*
|
|
202
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
203
|
-
* cdk: {
|
|
204
|
-
* restApi: {
|
|
205
|
-
* description: "My api"
|
|
206
|
-
* }
|
|
207
|
-
* }
|
|
208
|
-
* });
|
|
209
|
-
* ```
|
|
210
|
-
*/
|
|
211
|
-
restApi?: apig.IRestApi | apig.RestApiProps;
|
|
212
|
-
/**
|
|
213
|
-
* If you are importing an existing API Gateway REST API project, you can import existing route paths by providing a list of paths with their corresponding resource ids.
|
|
214
|
-
*
|
|
215
|
-
* @example
|
|
216
|
-
* ```js
|
|
217
|
-
* import { RestApi } from "aws-cdk-lib/aws-apigateway";
|
|
218
|
-
*
|
|
219
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
220
|
-
* cdk: {
|
|
221
|
-
* restApi: RestApi.fromRestApiAttributes(stack, "ImportedApi", {
|
|
222
|
-
* restApiId,
|
|
223
|
-
* rootResourceId,
|
|
224
|
-
* }),
|
|
225
|
-
* importedPaths: {
|
|
226
|
-
* "/notes": "slx2bn",
|
|
227
|
-
* "/users": "uu8xs3",
|
|
228
|
-
* },
|
|
229
|
-
* }
|
|
230
|
-
* });
|
|
231
|
-
* ```
|
|
232
|
-
*
|
|
233
|
-
* API Gateway REST API is structured in a tree structure:
|
|
234
|
-
* - Each path part is a separate API Gateway resource object.
|
|
235
|
-
* - And a path part is a child resource of the preceding part.
|
|
236
|
-
* So the part path /notes, is a child resource of the root resource /. And /notes/{noteId} is a child resource of /notes. If /notes has been created in the imported API, you have to import it before creating the /notes/{noteId} child route.
|
|
237
|
-
*/
|
|
238
|
-
importedPaths?: { [path: string]: string };
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export type ApiGatewayV1ApiRouteProps<AuthorizerKeys> =
|
|
243
|
-
| FunctionInlineDefinition
|
|
244
|
-
| ApiGatewayV1ApiFunctionRouteProps<AuthorizerKeys>;
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Specify a function route handler and configure additional options
|
|
248
|
-
*
|
|
249
|
-
* @example
|
|
250
|
-
* ```js
|
|
251
|
-
* api.addRoutes(props.stack, {
|
|
252
|
-
* "GET /notes/{id}": {
|
|
253
|
-
* type: "function",
|
|
254
|
-
* function: "src/get.main",
|
|
255
|
-
* }
|
|
256
|
-
* });
|
|
257
|
-
* ```
|
|
258
|
-
*/
|
|
259
|
-
export interface ApiGatewayV1ApiFunctionRouteProps<AuthorizerKeys = never> {
|
|
260
|
-
function?: FunctionDefinition;
|
|
261
|
-
authorizer?:
|
|
262
|
-
| "none"
|
|
263
|
-
| "iam"
|
|
264
|
-
| (string extends AuthorizerKeys ? never : AuthorizerKeys);
|
|
265
|
-
authorizationScopes?: string[];
|
|
266
|
-
cdk?: {
|
|
267
|
-
method?: Omit<
|
|
268
|
-
apig.MethodOptions,
|
|
269
|
-
"authorizer" | "authorizationType" | "authorizationScopes"
|
|
270
|
-
>;
|
|
271
|
-
integration?: apig.LambdaIntegrationOptions;
|
|
272
|
-
/**
|
|
273
|
-
* Use an existing Lambda function.
|
|
274
|
-
*/
|
|
275
|
-
function?: lambda.IFunction;
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export type ApiGatewayV1ApiAuthorizer =
|
|
280
|
-
| ApiGatewayV1ApiUserPoolsAuthorizer
|
|
281
|
-
| ApiGatewayV1ApiLambdaTokenAuthorizer
|
|
282
|
-
| ApiGatewayV1ApiLambdaRequestAuthorizer;
|
|
283
|
-
|
|
284
|
-
interface ApiGatewayV1ApiBaseAuthorizer {
|
|
285
|
-
/**
|
|
286
|
-
* The name of the authorizer.
|
|
287
|
-
*/
|
|
288
|
-
name?: string;
|
|
289
|
-
/**
|
|
290
|
-
* The amount of time the results are cached.
|
|
291
|
-
* @default Not cached
|
|
292
|
-
*/
|
|
293
|
-
resultsCacheTtl?: Duration;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Specify a user pools authorizer and configure additional options.
|
|
298
|
-
*
|
|
299
|
-
* @example
|
|
300
|
-
* ```js
|
|
301
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
302
|
-
* authorizers: {
|
|
303
|
-
* MyAuthorizer: {
|
|
304
|
-
* type: "user_pools",
|
|
305
|
-
* userPoolIds: [userPool.userPoolId],
|
|
306
|
-
* },
|
|
307
|
-
* },
|
|
308
|
-
* });
|
|
309
|
-
* ```
|
|
310
|
-
*/
|
|
311
|
-
export interface ApiGatewayV1ApiUserPoolsAuthorizer
|
|
312
|
-
extends ApiGatewayV1ApiBaseAuthorizer {
|
|
313
|
-
/**
|
|
314
|
-
* String literal to signify that the authorizer is user pool authorizer.
|
|
315
|
-
*/
|
|
316
|
-
type: "user_pools";
|
|
317
|
-
/**
|
|
318
|
-
* The ids of the user pools to use for authorization.
|
|
319
|
-
*/
|
|
320
|
-
userPoolIds?: string[];
|
|
321
|
-
/**
|
|
322
|
-
* The identity source for which authorization is requested.
|
|
323
|
-
*/
|
|
324
|
-
identitySource?: string;
|
|
325
|
-
cdk?: {
|
|
326
|
-
/**
|
|
327
|
-
* This allows you to override the default settings this construct uses internally to create the authorizer.
|
|
328
|
-
*/
|
|
329
|
-
authorizer: apig.CognitoUserPoolsAuthorizer;
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Specify a Lambda TOKEN authorizer and configure additional options.
|
|
335
|
-
*
|
|
336
|
-
* @example
|
|
337
|
-
* ```js
|
|
338
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
339
|
-
* authorizers: {
|
|
340
|
-
* MyAuthorizer: {
|
|
341
|
-
* type: "lambda_token",
|
|
342
|
-
* function: new Function(stack, "Authorizer", {
|
|
343
|
-
* handler: "test/lambda.handler"
|
|
344
|
-
* }),
|
|
345
|
-
* identitySources: [apig.IdentitySource.header("Authorization")],
|
|
346
|
-
* },
|
|
347
|
-
* },
|
|
348
|
-
* });
|
|
349
|
-
* ```
|
|
350
|
-
*/
|
|
351
|
-
export interface ApiGatewayV1ApiLambdaTokenAuthorizer
|
|
352
|
-
extends ApiGatewayV1ApiBaseAuthorizer {
|
|
353
|
-
/**
|
|
354
|
-
* String literal to signify that the authorizer is Lambda TOKEN authorizer.
|
|
355
|
-
*/
|
|
356
|
-
type: "lambda_token";
|
|
357
|
-
/**
|
|
358
|
-
* Used to create the authorizer function
|
|
359
|
-
*/
|
|
360
|
-
function?: Fn;
|
|
361
|
-
/**
|
|
362
|
-
* The identity source for which authorization is requested.
|
|
363
|
-
*/
|
|
364
|
-
identitySource?: string;
|
|
365
|
-
/**
|
|
366
|
-
* An regex to be matched against the authorization token.
|
|
367
|
-
*
|
|
368
|
-
* Note that when matched, the authorizer lambda is invoked, otherwise a 401 Unauthorized is returned to the client.
|
|
369
|
-
*/
|
|
370
|
-
validationRegex?: string;
|
|
371
|
-
cdk?: {
|
|
372
|
-
/**
|
|
373
|
-
* An IAM role for API Gateway to assume before calling the Lambda-based authorizer.
|
|
374
|
-
*/
|
|
375
|
-
assumeRole?: iam.IRole;
|
|
376
|
-
/**
|
|
377
|
-
* This allows you to override the default settings this construct uses internally to create the authorizer.
|
|
378
|
-
*/
|
|
379
|
-
authorizer?: apig.TokenAuthorizer;
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Specify a Lambda REQUEST authorizer and configure additional options.
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
* ```js
|
|
388
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
389
|
-
* authorizers: {
|
|
390
|
-
* MyAuthorizer: {
|
|
391
|
-
* type: "lambda_request",
|
|
392
|
-
* function: new Function(stack, "Authorizer", {
|
|
393
|
-
* handler: "test/lambda.handler"
|
|
394
|
-
* }),
|
|
395
|
-
* identitySources: [apig.IdentitySource.header("Authorization")],
|
|
396
|
-
* },
|
|
397
|
-
* },
|
|
398
|
-
* });
|
|
399
|
-
* ```
|
|
400
|
-
*/
|
|
401
|
-
export interface ApiGatewayV1ApiLambdaRequestAuthorizer
|
|
402
|
-
extends ApiGatewayV1ApiBaseAuthorizer {
|
|
403
|
-
/**
|
|
404
|
-
* String literal to signify that the authorizer is Lambda REQUEST authorizer.
|
|
405
|
-
*/
|
|
406
|
-
type: "lambda_request";
|
|
407
|
-
/**
|
|
408
|
-
* Used to create the authorizer function
|
|
409
|
-
*/
|
|
410
|
-
function?: Fn;
|
|
411
|
-
/**
|
|
412
|
-
* The identity sources for which authorization is requested.
|
|
413
|
-
*/
|
|
414
|
-
identitySources?: string[];
|
|
415
|
-
cdk?: {
|
|
416
|
-
/**
|
|
417
|
-
* An IAM role for API Gateway to assume before calling the Lambda-based authorizer.
|
|
418
|
-
*/
|
|
419
|
-
assumeRole?: iam.IRole;
|
|
420
|
-
/**
|
|
421
|
-
* This allows you to override the default settings this construct uses internally to create the authorizer.
|
|
422
|
-
*/
|
|
423
|
-
authorizer?: apig.TokenAuthorizer;
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* The customDomain for this API. SST currently supports domains that are configured using Route 53. If your domains are hosted elsewhere, you can [follow this guide to migrate them to Route 53](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/MigratingDNS.html).
|
|
429
|
-
*
|
|
430
|
-
* @example
|
|
431
|
-
* ```js
|
|
432
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
433
|
-
* customDomain: "api.domain.com",
|
|
434
|
-
* });
|
|
435
|
-
* ```
|
|
436
|
-
*
|
|
437
|
-
* @example
|
|
438
|
-
* ```js
|
|
439
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
440
|
-
* customDomain: {
|
|
441
|
-
* domainName: "api.domain.com",
|
|
442
|
-
* hostedZone: "domain.com",
|
|
443
|
-
* endpointType: EndpointType.EDGE,
|
|
444
|
-
* path: "v1",
|
|
445
|
-
* }
|
|
446
|
-
* });
|
|
447
|
-
* ```
|
|
448
|
-
*
|
|
449
|
-
* Note that, SST automatically creates a Route 53 A record in the hosted zone to point the custom domain to the API Gateway domain.
|
|
450
|
-
*/
|
|
451
|
-
export interface ApiGatewayV1ApiCustomDomainProps {
|
|
452
|
-
/**
|
|
453
|
-
* The domain to be assigned to the API endpoint.
|
|
454
|
-
*/
|
|
455
|
-
domainName?: string;
|
|
456
|
-
/**
|
|
457
|
-
* The hosted zone in Route 53 that contains the domain.
|
|
458
|
-
*
|
|
459
|
-
* By default, SST will look for a hosted zone by stripping out the first part of the domainName that's passed in. So, if your domainName is `api.domain.com`, SST will default the hostedZone to `domain.com`.
|
|
460
|
-
*/
|
|
461
|
-
hostedZone?: string;
|
|
462
|
-
/**
|
|
463
|
-
* The base mapping for the custom domain. For example, by setting the `domainName` to `api.domain.com` and `path` to `v1`, the custom domain URL for the API will become `https://api.domain.com/v1`. If the path is not set, the custom domain URL will be `https://api.domain.com`.
|
|
464
|
-
*
|
|
465
|
-
* :::caution
|
|
466
|
-
* You cannot change the path once it has been set.
|
|
467
|
-
* :::
|
|
468
|
-
*
|
|
469
|
-
* Note, if the `path` was not defined initially, it cannot be defined later. If the `path` was initially defined, it cannot be later changed to _undefined_. Instead, you'd need to remove the `customDomain` option from the construct, deploy it. And then set it to the new path value.
|
|
470
|
-
*/
|
|
471
|
-
path?: string;
|
|
472
|
-
/**
|
|
473
|
-
* The type of endpoint for this DomainName.
|
|
474
|
-
* @default `regional`
|
|
475
|
-
*/
|
|
476
|
-
endpointType?: Lowercase<keyof typeof apig.EndpointType>;
|
|
477
|
-
mtls?: {
|
|
478
|
-
/**
|
|
479
|
-
* The bucket that the trust store is hosted in.
|
|
480
|
-
*/
|
|
481
|
-
bucket: Bucket;
|
|
482
|
-
/**
|
|
483
|
-
* The key in S3 to look at for the trust store.
|
|
484
|
-
*/
|
|
485
|
-
key: string;
|
|
486
|
-
/**
|
|
487
|
-
* The version of the S3 object that contains your truststore.
|
|
488
|
-
*
|
|
489
|
-
* To specify a version, you must have versioning enabled for the S3 bucket.
|
|
490
|
-
*/
|
|
491
|
-
version?: string;
|
|
492
|
-
};
|
|
493
|
-
/**
|
|
494
|
-
* The Transport Layer Security (TLS) version + cipher suite for this domain name.
|
|
495
|
-
* @default `TLS 1.0`
|
|
496
|
-
*/
|
|
497
|
-
securityPolicy?: "TLS 1.0" | "TLS 1.2";
|
|
498
|
-
cdk?: {
|
|
499
|
-
/**
|
|
500
|
-
* Import the underlying API Gateway custom domain names.
|
|
501
|
-
*/
|
|
502
|
-
domainName?: apig.IDomainName;
|
|
503
|
-
/**
|
|
504
|
-
* Import the underlying Route 53 hosted zone.
|
|
505
|
-
*/
|
|
506
|
-
hostedZone?: route53.IHostedZone;
|
|
507
|
-
/**
|
|
508
|
-
* Import the underlying ACM certificate.
|
|
509
|
-
*/
|
|
510
|
-
certificate?: acm.ICertificate;
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/////////////////////
|
|
515
|
-
// Construct
|
|
516
|
-
/////////////////////
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
*
|
|
520
|
-
* The `ApiGatewayV1Api` construct is a higher level CDK construct that makes it easy to create an API Gateway REST API.
|
|
521
|
-
*
|
|
522
|
-
* @example
|
|
523
|
-
*
|
|
524
|
-
* ```js
|
|
525
|
-
* import { ApiGatewayV1Api } from "@serverless-stack/resources";
|
|
526
|
-
*
|
|
527
|
-
* new ApiGatewayV1Api(stack, "Api", {
|
|
528
|
-
* routes: {
|
|
529
|
-
* "GET /notes" : "src/list.main",
|
|
530
|
-
* "POST /notes" : "src/create.main",
|
|
531
|
-
* "GET /notes/{id}": "src/get.main",
|
|
532
|
-
* "PUT /notes/{id}": "src/update.main",
|
|
533
|
-
* "DELETE /notes/{id}": "src/delete.main",
|
|
534
|
-
* },
|
|
535
|
-
* });
|
|
536
|
-
* ```
|
|
537
|
-
*/
|
|
538
|
-
export class ApiGatewayV1Api<
|
|
539
|
-
Authorizers extends Record<string, ApiGatewayV1ApiAuthorizer> = Record<
|
|
540
|
-
string,
|
|
541
|
-
never
|
|
542
|
-
>
|
|
543
|
-
>
|
|
544
|
-
extends Construct
|
|
545
|
-
implements SSTConstruct {
|
|
546
|
-
public readonly id: string;
|
|
547
|
-
public readonly cdk: {
|
|
548
|
-
/**
|
|
549
|
-
* The internally created rest API
|
|
550
|
-
*/
|
|
551
|
-
restApi: apig.RestApi;
|
|
552
|
-
/**
|
|
553
|
-
* The internally created log group
|
|
554
|
-
*/
|
|
555
|
-
accessLogGroup?: logs.LogGroup;
|
|
556
|
-
/**
|
|
557
|
-
* The internally created domain name
|
|
558
|
-
*/
|
|
559
|
-
domainName?: apig.DomainName;
|
|
560
|
-
/**
|
|
561
|
-
* The internally created certificate
|
|
562
|
-
*/
|
|
563
|
-
certificate?: acm.Certificate | acm.DnsValidatedCertificate;
|
|
564
|
-
};
|
|
565
|
-
private _deployment?: apig.Deployment;
|
|
566
|
-
private _customDomainUrl?: string;
|
|
567
|
-
private importedResources: { [path: string]: apig.IResource } = {};
|
|
568
|
-
private props: ApiGatewayV1ApiProps<Authorizers>;
|
|
569
|
-
private functions: { [key: string]: Fn | lambda.IFunction } = {};
|
|
570
|
-
private authorizersData: Record<string, apig.IAuthorizer> = {};
|
|
571
|
-
private bindingForAllRoutes: SSTConstruct[] = [];
|
|
572
|
-
private permissionsAttachedForAllRoutes: Permissions[] = [];
|
|
573
|
-
|
|
574
|
-
constructor(
|
|
575
|
-
scope: Construct,
|
|
576
|
-
id: string,
|
|
577
|
-
props?: ApiGatewayV1ApiProps<Authorizers>
|
|
578
|
-
) {
|
|
579
|
-
super(scope, props?.cdk?.id || id);
|
|
580
|
-
|
|
581
|
-
this.id = id;
|
|
582
|
-
this.props = props || {};
|
|
583
|
-
this.cdk = {} as any;
|
|
584
|
-
|
|
585
|
-
this.createRestApi();
|
|
586
|
-
this.addAuthorizers(this.props.authorizers || ({} as Authorizers));
|
|
587
|
-
this.addRoutes(this, this.props.routes || {});
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* The AWS generated URL of the Api.
|
|
592
|
-
*/
|
|
593
|
-
public get url(): string {
|
|
594
|
-
return this.cdk.restApi.url;
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
* If custom domain is enabled, this is the custom domain URL of the Api.
|
|
599
|
-
*
|
|
600
|
-
* :::note
|
|
601
|
-
* If you are setting the base mapping for the custom domain, you need to include the trailing slash while using the custom domain URL. For example, if the [`domainName`](#domainname) is set to `api.domain.com` and the [`path`](#path) is `v1`, the custom domain URL of the API will be `https://api.domain.com/v1/`.
|
|
602
|
-
* :::
|
|
603
|
-
*/
|
|
604
|
-
public get customDomainUrl(): string | undefined {
|
|
605
|
-
return this._customDomainUrl;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* The routes for the Api
|
|
610
|
-
*/
|
|
611
|
-
public get routes(): string[] {
|
|
612
|
-
return Object.keys(this.functions);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* The ARN of the internally created API Gateway REST API
|
|
617
|
-
*/
|
|
618
|
-
public get restApiArn(): string {
|
|
619
|
-
const stack = Stack.of(this);
|
|
620
|
-
return `arn:${stack.partition}:apigateway:${stack.region}::/restapis/${this.cdk.restApi.restApiId}`;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
* The id of the internally created API Gateway REST API
|
|
625
|
-
*/
|
|
626
|
-
public get restApiId(): string {
|
|
627
|
-
return this.cdk.restApi.restApiId;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
/**
|
|
631
|
-
* Adds routes to the Api after it has been created.
|
|
632
|
-
*
|
|
633
|
-
* @example
|
|
634
|
-
* ```js
|
|
635
|
-
* api.addRoutes(stack, {
|
|
636
|
-
* "GET /notes/{id}": "src/get.main",
|
|
637
|
-
* "PUT /notes/{id}": "src/update.main",
|
|
638
|
-
* "DELETE /notes/{id}": "src/delete.main",
|
|
639
|
-
* });
|
|
640
|
-
* ```
|
|
641
|
-
*/
|
|
642
|
-
public addRoutes(
|
|
643
|
-
scope: Construct,
|
|
644
|
-
routes: Record<string, ApiGatewayV1ApiRouteProps<keyof Authorizers>>
|
|
645
|
-
): void {
|
|
646
|
-
Object.keys(routes).forEach((routeKey: string) =>
|
|
647
|
-
this.addRoute(scope, routeKey, routes[routeKey])
|
|
648
|
-
);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
/**
|
|
652
|
-
* Get the instance of the internally created Function, for a given route key where the `routeKey` is the key used to define a route. For example, `GET /notes`.
|
|
653
|
-
*
|
|
654
|
-
* @example
|
|
655
|
-
* ```js
|
|
656
|
-
* const api = new ApiGatewayV1Api(stack, "Api", {
|
|
657
|
-
* routes: {
|
|
658
|
-
* "GET /notes": "src/list.main",
|
|
659
|
-
* },
|
|
660
|
-
* });
|
|
661
|
-
*
|
|
662
|
-
* const listFunction = api.getFunction("GET /notes");
|
|
663
|
-
* ```
|
|
664
|
-
*/
|
|
665
|
-
public getFunction(routeKey: string): Fn | undefined {
|
|
666
|
-
const fn = this.functions[this.normalizeRouteKey(routeKey)];
|
|
667
|
-
if (fn instanceof Fn) {
|
|
668
|
-
return fn;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
/**
|
|
673
|
-
* Binds the given list of resources to all the routes.
|
|
674
|
-
*
|
|
675
|
-
* @example
|
|
676
|
-
*
|
|
677
|
-
* ```js
|
|
678
|
-
* api.bind([STRIPE_KEY, bucket]);
|
|
679
|
-
* ```
|
|
680
|
-
*/
|
|
681
|
-
public bind(constructs: SSTConstruct[]) {
|
|
682
|
-
Object.values(this.functions).forEach((fn) => {
|
|
683
|
-
if (fn instanceof Fn) {
|
|
684
|
-
fn.bind(constructs)
|
|
685
|
-
}
|
|
686
|
-
});
|
|
687
|
-
this.bindingForAllRoutes.push(...constructs);
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
/**
|
|
691
|
-
* Binds the given list of resources to a specific route.
|
|
692
|
-
*
|
|
693
|
-
* @example
|
|
694
|
-
* ```js
|
|
695
|
-
* const api = new Api(stack, "Api", {
|
|
696
|
-
* routes: {
|
|
697
|
-
* "GET /notes": "src/list.main",
|
|
698
|
-
* },
|
|
699
|
-
* });
|
|
700
|
-
*
|
|
701
|
-
* api.bindToRoute("GET /notes", [STRIPE_KEY, bucket]);
|
|
702
|
-
* ```
|
|
703
|
-
*
|
|
704
|
-
*/
|
|
705
|
-
public bindToRoute(
|
|
706
|
-
routeKey: string,
|
|
707
|
-
constructs: SSTConstruct[]
|
|
708
|
-
): void {
|
|
709
|
-
const fn = this.getFunction(routeKey);
|
|
710
|
-
if (!fn) {
|
|
711
|
-
throw new Error(
|
|
712
|
-
`Failed to bind resources. Route "${routeKey}" does not exist.`
|
|
713
|
-
);
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
fn.bind(constructs);
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
/**
|
|
720
|
-
* Attaches the given list of permissions to all the routes. This allows the functions to access other AWS resources.
|
|
721
|
-
*
|
|
722
|
-
* @example
|
|
723
|
-
*
|
|
724
|
-
* ```js
|
|
725
|
-
* api.attachPermissions(["s3"]);
|
|
726
|
-
* ```
|
|
727
|
-
*/
|
|
728
|
-
public attachPermissions(permissions: Permissions): void {
|
|
729
|
-
Object.values(this.functions).forEach((fn) => {
|
|
730
|
-
if (fn instanceof Fn) {
|
|
731
|
-
fn.attachPermissions(permissions);
|
|
732
|
-
}
|
|
733
|
-
});
|
|
734
|
-
this.permissionsAttachedForAllRoutes.push(permissions);
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* Attaches the given list of permissions to a specific route. This allows that function to access other AWS resources.
|
|
739
|
-
*
|
|
740
|
-
* @example
|
|
741
|
-
* ```js
|
|
742
|
-
* const api = new ApiGatewayV1Api(stack, "Api", {
|
|
743
|
-
* routes: {
|
|
744
|
-
* "GET /notes": "src/list.main",
|
|
745
|
-
* },
|
|
746
|
-
* });
|
|
747
|
-
*
|
|
748
|
-
* api.attachPermissionsToRoute("GET /notes", ["s3"]);
|
|
749
|
-
* ```
|
|
750
|
-
*/
|
|
751
|
-
public attachPermissionsToRoute(
|
|
752
|
-
routeKey: string,
|
|
753
|
-
permissions: Permissions
|
|
754
|
-
): void {
|
|
755
|
-
const fn = this.getFunction(routeKey);
|
|
756
|
-
if (!fn) {
|
|
757
|
-
throw new Error(
|
|
758
|
-
`Failed to attach permissions. Route "${routeKey}" does not exist.`
|
|
759
|
-
);
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
fn.attachPermissions(permissions);
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
public getConstructMetadata() {
|
|
766
|
-
return {
|
|
767
|
-
type: "ApiGatewayV1Api" as const,
|
|
768
|
-
data: {
|
|
769
|
-
customDomainUrl: this._customDomainUrl,
|
|
770
|
-
url: this.cdk.restApi.url,
|
|
771
|
-
restApiId: this.cdk.restApi.restApiId,
|
|
772
|
-
routes: Object.entries(this.functions).map(([key, data]) => {
|
|
773
|
-
return {
|
|
774
|
-
type: "function" as const,
|
|
775
|
-
route: key,
|
|
776
|
-
fn: getFunctionRef(data),
|
|
777
|
-
};
|
|
778
|
-
}),
|
|
779
|
-
},
|
|
780
|
-
};
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
/** @internal */
|
|
784
|
-
public getFunctionBinding() {
|
|
785
|
-
return {
|
|
786
|
-
clientPackage: "api",
|
|
787
|
-
variables: {
|
|
788
|
-
url: {
|
|
789
|
-
environment: this.customDomainUrl || this.url,
|
|
790
|
-
parameter: this.customDomainUrl || this.url,
|
|
791
|
-
},
|
|
792
|
-
},
|
|
793
|
-
permissions: {},
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
private createRestApi() {
|
|
798
|
-
const { cdk, cors, accessLog, customDomain } = this.props;
|
|
799
|
-
const id = this.node.id;
|
|
800
|
-
const app = this.node.root as App;
|
|
801
|
-
|
|
802
|
-
if (isCDKConstruct(cdk?.restApi)) {
|
|
803
|
-
if (cors !== undefined) {
|
|
804
|
-
throw new Error(
|
|
805
|
-
`Cannot configure the "cors" when the "restApi" is imported`
|
|
806
|
-
);
|
|
807
|
-
}
|
|
808
|
-
if (accessLog !== undefined) {
|
|
809
|
-
throw new Error(
|
|
810
|
-
`Cannot configure the "accessLog" when the "restApi" is imported`
|
|
811
|
-
);
|
|
812
|
-
}
|
|
813
|
-
if (customDomain !== undefined) {
|
|
814
|
-
throw new Error(
|
|
815
|
-
`Cannot configure the "customDomain" when the "restApi" is imported`
|
|
816
|
-
);
|
|
817
|
-
}
|
|
818
|
-
this.cdk.restApi = cdk?.restApi as apig.RestApi;
|
|
819
|
-
|
|
820
|
-
// Create an API Gateway deployment resource to trigger a deployment
|
|
821
|
-
this._deployment = new apig.Deployment(this, "Deployment", {
|
|
822
|
-
api: this.cdk.restApi,
|
|
823
|
-
});
|
|
824
|
-
const cfnDeployment = this._deployment.node
|
|
825
|
-
.defaultChild as apig.CfnDeployment;
|
|
826
|
-
cfnDeployment.stageName = app.stage;
|
|
827
|
-
|
|
828
|
-
if (cdk?.importedPaths) {
|
|
829
|
-
this.importResources(cdk?.importedPaths);
|
|
830
|
-
}
|
|
831
|
-
} else {
|
|
832
|
-
const restApiProps = (cdk?.restApi || {}) as apig.RestApiProps;
|
|
833
|
-
|
|
834
|
-
// Validate input
|
|
835
|
-
if (cdk?.importedPaths !== undefined) {
|
|
836
|
-
throw new Error(`Cannot import route paths when creating a new API.`);
|
|
837
|
-
}
|
|
838
|
-
if (customDomain !== undefined && restApiProps.domainName !== undefined) {
|
|
839
|
-
throw new Error(
|
|
840
|
-
`Use either the "customDomain" or the "restApi.domainName" to configure the Api domain. Do not use both.`
|
|
841
|
-
);
|
|
842
|
-
}
|
|
843
|
-
if (
|
|
844
|
-
cors !== undefined &&
|
|
845
|
-
restApiProps.defaultCorsPreflightOptions !== undefined
|
|
846
|
-
) {
|
|
847
|
-
throw new Error(
|
|
848
|
-
`Use either the "cors" or the "restApi.defaultCorsPreflightOptions" to configure the Api's CORS config. Do not use both.`
|
|
849
|
-
);
|
|
850
|
-
}
|
|
851
|
-
if (
|
|
852
|
-
accessLog !== undefined &&
|
|
853
|
-
restApiProps.deployOptions?.accessLogDestination !== undefined
|
|
854
|
-
) {
|
|
855
|
-
throw new Error(
|
|
856
|
-
`Use either the "accessLog" or the "restApi.deployOptions.accessLogDestination" to configure the Api's access log. Do not use both.`
|
|
857
|
-
);
|
|
858
|
-
}
|
|
859
|
-
if (
|
|
860
|
-
accessLog !== undefined &&
|
|
861
|
-
restApiProps.deployOptions?.accessLogFormat !== undefined
|
|
862
|
-
) {
|
|
863
|
-
throw new Error(
|
|
864
|
-
`Use either the "accessLog" or the "restApi.deployOptions.accessLogFormat" to configure the Api's access log. Do not use both.`
|
|
865
|
-
);
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
const stageName =
|
|
869
|
-
restApiProps.deployOptions?.stageName || (this.node.root as App).stage;
|
|
870
|
-
|
|
871
|
-
const accessLogData = apigV1AccessLog.buildAccessLogData(this, accessLog);
|
|
872
|
-
|
|
873
|
-
this.cdk.accessLogGroup = accessLogData?.logGroup;
|
|
874
|
-
|
|
875
|
-
this.cdk.restApi = new apig.RestApi(this, "Api", {
|
|
876
|
-
restApiName: app.logicalPrefixedName(id),
|
|
877
|
-
...restApiProps,
|
|
878
|
-
domainName: restApiProps.domainName,
|
|
879
|
-
defaultCorsPreflightOptions:
|
|
880
|
-
restApiProps.defaultCorsPreflightOptions ||
|
|
881
|
-
this.buildCorsConfig(cors),
|
|
882
|
-
deployOptions: {
|
|
883
|
-
...(restApiProps.deployOptions || {}),
|
|
884
|
-
accessLogDestination:
|
|
885
|
-
restApiProps.deployOptions?.accessLogDestination ||
|
|
886
|
-
accessLogData?.destination,
|
|
887
|
-
accessLogFormat:
|
|
888
|
-
restApiProps.deployOptions?.accessLogFormat ||
|
|
889
|
-
accessLogData?.format,
|
|
890
|
-
|
|
891
|
-
// default to the name of the sage
|
|
892
|
-
stageName: stageName,
|
|
893
|
-
|
|
894
|
-
// default to true
|
|
895
|
-
tracingEnabled:
|
|
896
|
-
restApiProps.deployOptions?.tracingEnabled === undefined
|
|
897
|
-
? true
|
|
898
|
-
: restApiProps.deployOptions?.tracingEnabled,
|
|
899
|
-
},
|
|
900
|
-
});
|
|
901
|
-
|
|
902
|
-
this.createCustomDomain(customDomain);
|
|
903
|
-
this.createGatewayResponseForCors(cors);
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
private buildCorsConfig(cors?: boolean): apig.CorsOptions | undefined {
|
|
908
|
-
// Case: cors is false
|
|
909
|
-
if (cors === false) {
|
|
910
|
-
return undefined;
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
// Case: cors is true or undefined
|
|
914
|
-
return {
|
|
915
|
-
allowHeaders: ["*"],
|
|
916
|
-
allowOrigins: apig.Cors.ALL_ORIGINS,
|
|
917
|
-
allowMethods: apig.Cors.ALL_METHODS,
|
|
918
|
-
} as apig.CorsOptions;
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
private createGatewayResponseForCors(cors?: boolean): void {
|
|
922
|
-
if (!cors) {
|
|
923
|
-
return;
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
this.cdk.restApi.addGatewayResponse("GatewayResponseDefault4XX", {
|
|
927
|
-
type: apig.ResponseType.DEFAULT_4XX,
|
|
928
|
-
responseHeaders: {
|
|
929
|
-
"Access-Control-Allow-Origin": "'*'",
|
|
930
|
-
"Access-Control-Allow-Headers": "'*'",
|
|
931
|
-
},
|
|
932
|
-
});
|
|
933
|
-
|
|
934
|
-
this.cdk.restApi.addGatewayResponse("GatewayResponseDefault5XX", {
|
|
935
|
-
type: apig.ResponseType.DEFAULT_5XX,
|
|
936
|
-
responseHeaders: {
|
|
937
|
-
"Access-Control-Allow-Origin": "'*'",
|
|
938
|
-
"Access-Control-Allow-Headers": "'*'",
|
|
939
|
-
},
|
|
940
|
-
});
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
private createCustomDomain(
|
|
944
|
-
customDomain?: string | ApiGatewayV1ApiCustomDomainProps
|
|
945
|
-
): void {
|
|
946
|
-
// Case: customDomain is not set
|
|
947
|
-
if (customDomain === undefined) {
|
|
948
|
-
return;
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
// To be implemented: to allow more flexible use cases, SST should support 3 more use cases:
|
|
952
|
-
// 1. Allow user passing in `hostedZone` object. The use case is when there are multiple
|
|
953
|
-
// HostedZones with the same domain, but one is public, and one is private.
|
|
954
|
-
// 2. Allow user passing in `certificate` object. The use case is for user to create wildcard
|
|
955
|
-
// certificate or using an imported certificate.
|
|
956
|
-
// 3. Allow user passing in `apigDomainName` object. The use case is a user creates multiple API
|
|
957
|
-
// endpoints, and is mapping them under the same custom domain. `sst.Api` needs to expose the
|
|
958
|
-
// `apigDomainName` construct created in the first Api, and lets user pass it in when creating
|
|
959
|
-
// the second Api.
|
|
960
|
-
|
|
961
|
-
let domainName,
|
|
962
|
-
hostedZone,
|
|
963
|
-
hostedZoneDomain,
|
|
964
|
-
certificate,
|
|
965
|
-
apigDomainName,
|
|
966
|
-
basePath,
|
|
967
|
-
endpointType,
|
|
968
|
-
mtls,
|
|
969
|
-
securityPolicy;
|
|
970
|
-
|
|
971
|
-
/////////////////////
|
|
972
|
-
// Parse input
|
|
973
|
-
/////////////////////
|
|
974
|
-
|
|
975
|
-
// Case: customDomain is a string
|
|
976
|
-
if (typeof customDomain === "string") {
|
|
977
|
-
// validate: customDomain is a TOKEN string
|
|
978
|
-
// ie. imported SSM value: ssm.StringParameter.valueForStringParameter()
|
|
979
|
-
if (cdk.Token.isUnresolved(customDomain)) {
|
|
980
|
-
throw new Error(
|
|
981
|
-
`You also need to specify the "hostedZone" if the "domainName" is passed in as a reference.`
|
|
982
|
-
);
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
domainName = customDomain;
|
|
986
|
-
this.assertDomainNameIsLowerCase(domainName);
|
|
987
|
-
hostedZoneDomain = customDomain.split(".").slice(1).join(".");
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
// Case: customDomain.domainName is a string
|
|
991
|
-
else if (customDomain.domainName) {
|
|
992
|
-
domainName = customDomain.domainName;
|
|
993
|
-
|
|
994
|
-
// parse customDomain.domainName
|
|
995
|
-
if (cdk.Token.isUnresolved(customDomain.domainName)) {
|
|
996
|
-
// If customDomain is a TOKEN string, "hostedZone" has to be passed in. This
|
|
997
|
-
// is because "hostedZone" cannot be parsed from a TOKEN value.
|
|
998
|
-
if (!customDomain.hostedZone && !customDomain.cdk?.hostedZone) {
|
|
999
|
-
throw new Error(
|
|
1000
|
-
`You also need to specify the "hostedZone" if the "domainName" is passed in as a reference.`
|
|
1001
|
-
);
|
|
1002
|
-
}
|
|
1003
|
-
domainName = customDomain.domainName;
|
|
1004
|
-
} else {
|
|
1005
|
-
domainName = customDomain.domainName;
|
|
1006
|
-
this.assertDomainNameIsLowerCase(domainName);
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
// parse customDomain.hostedZone
|
|
1010
|
-
if (customDomain.hostedZone && customDomain.cdk?.hostedZone) {
|
|
1011
|
-
throw new Error(
|
|
1012
|
-
`Use either the "customDomain.hostedZone" or the "customDomain.cdk.hostedZone" to configure the custom domain hosted zone. Do not use both.`
|
|
1013
|
-
);
|
|
1014
|
-
}
|
|
1015
|
-
if (customDomain.hostedZone) {
|
|
1016
|
-
hostedZoneDomain = customDomain.hostedZone;
|
|
1017
|
-
} else if (customDomain.cdk?.hostedZone) {
|
|
1018
|
-
hostedZone = customDomain.cdk?.hostedZone;
|
|
1019
|
-
} else {
|
|
1020
|
-
hostedZoneDomain = domainName.split(".").slice(1).join(".");
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
certificate = customDomain.cdk?.certificate;
|
|
1024
|
-
basePath = customDomain.path;
|
|
1025
|
-
endpointType = customDomain.endpointType;
|
|
1026
|
-
mtls = customDomain.mtls;
|
|
1027
|
-
securityPolicy = customDomain.securityPolicy;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
// Case: customDomain.domainName is a construct
|
|
1031
|
-
else if (customDomain.cdk?.domainName) {
|
|
1032
|
-
apigDomainName = customDomain.cdk.domainName;
|
|
1033
|
-
|
|
1034
|
-
// customDomain.domainName is imported
|
|
1035
|
-
if (
|
|
1036
|
-
apigDomainName &&
|
|
1037
|
-
(customDomain.hostedZone || customDomain.cdk?.hostedZone)
|
|
1038
|
-
) {
|
|
1039
|
-
throw new Error(
|
|
1040
|
-
`Cannot configure the "hostedZone" when the "domainName" is a construct`
|
|
1041
|
-
);
|
|
1042
|
-
}
|
|
1043
|
-
if (apigDomainName && customDomain.cdk?.certificate) {
|
|
1044
|
-
throw new Error(
|
|
1045
|
-
`Cannot configure the "certificate" when the "domainName" is a construct`
|
|
1046
|
-
);
|
|
1047
|
-
}
|
|
1048
|
-
if (apigDomainName && customDomain.endpointType) {
|
|
1049
|
-
throw new Error(
|
|
1050
|
-
`Cannot configure the "endpointType" when the "domainName" is a construct`
|
|
1051
|
-
);
|
|
1052
|
-
}
|
|
1053
|
-
if (apigDomainName && customDomain.mtls) {
|
|
1054
|
-
throw new Error(
|
|
1055
|
-
`Cannot configure the "mtls" when the "domainName" is a construct`
|
|
1056
|
-
);
|
|
1057
|
-
}
|
|
1058
|
-
if (apigDomainName && customDomain.securityPolicy) {
|
|
1059
|
-
throw new Error(
|
|
1060
|
-
`Cannot configure the "securityPolicy" when the "domainName" is a construct`
|
|
1061
|
-
);
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
basePath = customDomain.path;
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
/////////////////////
|
|
1068
|
-
// Find hosted zone
|
|
1069
|
-
/////////////////////
|
|
1070
|
-
if (!apigDomainName && !hostedZone) {
|
|
1071
|
-
// Look up hosted zone
|
|
1072
|
-
if (!hostedZone && hostedZoneDomain) {
|
|
1073
|
-
hostedZone = route53.HostedZone.fromLookup(this, "HostedZone", {
|
|
1074
|
-
domainName: hostedZoneDomain,
|
|
1075
|
-
});
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
/////////////////////
|
|
1080
|
-
// Create certificate
|
|
1081
|
-
/////////////////////
|
|
1082
|
-
if (!apigDomainName && !certificate) {
|
|
1083
|
-
if (endpointType === "edge") {
|
|
1084
|
-
certificate = new acm.DnsValidatedCertificate(
|
|
1085
|
-
this,
|
|
1086
|
-
"CrossRegionCertificate",
|
|
1087
|
-
{
|
|
1088
|
-
domainName: domainName as string,
|
|
1089
|
-
hostedZone: hostedZone as route53.IHostedZone,
|
|
1090
|
-
region: "us-east-1",
|
|
1091
|
-
}
|
|
1092
|
-
);
|
|
1093
|
-
} else {
|
|
1094
|
-
certificate = new acm.Certificate(this, "Certificate", {
|
|
1095
|
-
domainName: domainName as string,
|
|
1096
|
-
validation: acm.CertificateValidation.fromDns(hostedZone),
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
this.cdk.certificate = certificate;
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
/////////////////////
|
|
1103
|
-
// Create API Gateway domain name
|
|
1104
|
-
/////////////////////
|
|
1105
|
-
if (!apigDomainName && domainName) {
|
|
1106
|
-
// Create custom domain in API Gateway
|
|
1107
|
-
apigDomainName = new apig.DomainName(this, "DomainName", {
|
|
1108
|
-
domainName,
|
|
1109
|
-
certificate: certificate as acm.ICertificate,
|
|
1110
|
-
endpointType:
|
|
1111
|
-
endpointType &&
|
|
1112
|
-
apig.EndpointType[
|
|
1113
|
-
endpointType.toLocaleUpperCase() as keyof typeof apig.EndpointType
|
|
1114
|
-
],
|
|
1115
|
-
mtls: mtls && {
|
|
1116
|
-
...mtls,
|
|
1117
|
-
bucket: mtls.bucket.cdk.bucket,
|
|
1118
|
-
},
|
|
1119
|
-
securityPolicy:
|
|
1120
|
-
securityPolicy === "TLS 1.0"
|
|
1121
|
-
? apig.SecurityPolicy.TLS_1_0
|
|
1122
|
-
: securityPolicy === "TLS 1.2"
|
|
1123
|
-
? apig.SecurityPolicy.TLS_1_2
|
|
1124
|
-
: undefined,
|
|
1125
|
-
});
|
|
1126
|
-
this.cdk.domainName = apigDomainName;
|
|
1127
|
-
|
|
1128
|
-
// Create DNS record
|
|
1129
|
-
this.createARecords(
|
|
1130
|
-
hostedZone as route53.IHostedZone,
|
|
1131
|
-
domainName,
|
|
1132
|
-
apigDomainName
|
|
1133
|
-
);
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
/////////////////////
|
|
1137
|
-
// Create base mapping
|
|
1138
|
-
/////////////////////
|
|
1139
|
-
if (apigDomainName) {
|
|
1140
|
-
new apig.BasePathMapping(this, "BasePath", {
|
|
1141
|
-
domainName: apigDomainName,
|
|
1142
|
-
restApi: this.cdk.restApi,
|
|
1143
|
-
basePath,
|
|
1144
|
-
});
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
// Note: We only know the full custom domain if domainName is a string.
|
|
1148
|
-
// _customDomainUrl will be undefined if apigDomainName is imported.
|
|
1149
|
-
if (domainName && !cdk.Token.isUnresolved(domainName)) {
|
|
1150
|
-
this._customDomainUrl = basePath
|
|
1151
|
-
? `https://${domainName}/${basePath}/`
|
|
1152
|
-
: `https://${domainName}`;
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
private createARecords(
|
|
1157
|
-
hostedZone: route53.IHostedZone,
|
|
1158
|
-
domainName: string,
|
|
1159
|
-
apigDomain: apig.IDomainName
|
|
1160
|
-
) {
|
|
1161
|
-
// create DNS record
|
|
1162
|
-
const recordProps = {
|
|
1163
|
-
recordName: domainName,
|
|
1164
|
-
zone: hostedZone as route53.IHostedZone,
|
|
1165
|
-
target: route53.RecordTarget.fromAlias(
|
|
1166
|
-
new route53Targets.ApiGatewayDomain(apigDomain)
|
|
1167
|
-
),
|
|
1168
|
-
};
|
|
1169
|
-
const records = [
|
|
1170
|
-
new route53.ARecord(this, "AliasRecord", recordProps),
|
|
1171
|
-
new route53.AaaaRecord(this, "AliasRecordAAAA", recordProps),
|
|
1172
|
-
];
|
|
1173
|
-
// note: If domainName is a TOKEN string ie. ${TOKEN..}, the route53.ARecord
|
|
1174
|
-
// construct will append ".${hostedZoneName}" to the end of the domain.
|
|
1175
|
-
// This is because the construct tries to check if the record name
|
|
1176
|
-
// ends with the domain name. If not, it will append the domain name.
|
|
1177
|
-
// So, we need remove this behavior.
|
|
1178
|
-
if (cdk.Token.isUnresolved(domainName)) {
|
|
1179
|
-
records.forEach((record) => {
|
|
1180
|
-
const cfnRecord = record.node.defaultChild as route53.CfnRecordSet;
|
|
1181
|
-
cfnRecord.name = domainName;
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
private importResources(resources: { [path: string]: string }): void {
|
|
1187
|
-
Object.keys(resources).forEach((path) => {
|
|
1188
|
-
const resource = apig.Resource.fromResourceAttributes(
|
|
1189
|
-
this,
|
|
1190
|
-
`Resource_${path}`,
|
|
1191
|
-
{
|
|
1192
|
-
path,
|
|
1193
|
-
resourceId: resources[path],
|
|
1194
|
-
restApi: this.cdk.restApi,
|
|
1195
|
-
}
|
|
1196
|
-
);
|
|
1197
|
-
this.importedResources[path] = resource;
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
private getResourceForPath(path: string): apig.IResource {
|
|
1202
|
-
// Lookup exact match imported resource
|
|
1203
|
-
if (this.importedResources[path]) {
|
|
1204
|
-
return this.importedResources[path];
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
// Lookup parents matching imported resource first
|
|
1208
|
-
const parts = path.split("/");
|
|
1209
|
-
for (let i = parts.length; i >= 1; i--) {
|
|
1210
|
-
const partialPath = parts.slice(0, i).join("/");
|
|
1211
|
-
if (this.importedResources[partialPath]) {
|
|
1212
|
-
return this.importedResources[partialPath].resourceForPath(
|
|
1213
|
-
parts.slice(i).join("/")
|
|
1214
|
-
);
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
// Not child of imported resources, create off the root
|
|
1219
|
-
return this.cdk.restApi.root.resourceForPath(path);
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
|
-
private addAuthorizers(authorizers: Authorizers) {
|
|
1223
|
-
Object.entries(authorizers).forEach(([key, value]) => {
|
|
1224
|
-
if (key === "none") {
|
|
1225
|
-
throw new Error(`Cannot name an authorizer "none"`);
|
|
1226
|
-
} else if (key === "iam") {
|
|
1227
|
-
throw new Error(`Cannot name an authorizer "iam"`);
|
|
1228
|
-
} else if (value.type === "user_pools") {
|
|
1229
|
-
if (value.cdk?.authorizer) {
|
|
1230
|
-
this.authorizersData[key] = value.cdk.authorizer;
|
|
1231
|
-
} else {
|
|
1232
|
-
if (!value.userPoolIds) {
|
|
1233
|
-
throw new Error(`Missing "userPoolIds" for "${key}" authorizer`);
|
|
1234
|
-
}
|
|
1235
|
-
const userPools = value.userPoolIds.map((userPoolId) =>
|
|
1236
|
-
cognito.UserPool.fromUserPoolId(
|
|
1237
|
-
this,
|
|
1238
|
-
`${key}-ImportedUserPool`,
|
|
1239
|
-
userPoolId
|
|
1240
|
-
)
|
|
1241
|
-
);
|
|
1242
|
-
this.authorizersData[key] = new apig.CognitoUserPoolsAuthorizer(
|
|
1243
|
-
this,
|
|
1244
|
-
key,
|
|
1245
|
-
{
|
|
1246
|
-
cognitoUserPools: userPools,
|
|
1247
|
-
authorizerName: value.name,
|
|
1248
|
-
identitySource: value.identitySource,
|
|
1249
|
-
resultsCacheTtl: value.resultsCacheTtl
|
|
1250
|
-
? toCdkDuration(value.resultsCacheTtl)
|
|
1251
|
-
: cdk.Duration.seconds(0),
|
|
1252
|
-
}
|
|
1253
|
-
);
|
|
1254
|
-
}
|
|
1255
|
-
} else if (value.type === "lambda_token") {
|
|
1256
|
-
if (value.cdk?.authorizer) {
|
|
1257
|
-
this.authorizersData[key] = value.cdk.authorizer;
|
|
1258
|
-
} else {
|
|
1259
|
-
if (!value.function) {
|
|
1260
|
-
throw new Error(`Missing "function" for "${key}" authorizer`);
|
|
1261
|
-
}
|
|
1262
|
-
this.authorizersData[key] = new apig.TokenAuthorizer(this, key, {
|
|
1263
|
-
handler: value.function,
|
|
1264
|
-
authorizerName: value.name,
|
|
1265
|
-
identitySource: value.identitySource,
|
|
1266
|
-
validationRegex: value.validationRegex,
|
|
1267
|
-
assumeRole: value.cdk?.assumeRole,
|
|
1268
|
-
resultsCacheTtl: value.resultsCacheTtl
|
|
1269
|
-
? toCdkDuration(value.resultsCacheTtl)
|
|
1270
|
-
: cdk.Duration.seconds(0),
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
} else if (value.type === "lambda_request") {
|
|
1274
|
-
if (value.cdk?.authorizer) {
|
|
1275
|
-
this.authorizersData[key] = value.cdk.authorizer;
|
|
1276
|
-
} else {
|
|
1277
|
-
if (!value.function) {
|
|
1278
|
-
throw new Error(`Missing "function" for "${key}" authorizer`);
|
|
1279
|
-
} else if (!value.identitySources) {
|
|
1280
|
-
throw new Error(
|
|
1281
|
-
`Missing "identitySources" for "${key}" authorizer`
|
|
1282
|
-
);
|
|
1283
|
-
}
|
|
1284
|
-
this.authorizersData[key] = new apig.RequestAuthorizer(this, key, {
|
|
1285
|
-
handler: value.function,
|
|
1286
|
-
authorizerName: value.name,
|
|
1287
|
-
identitySources: value.identitySources,
|
|
1288
|
-
assumeRole: value.cdk?.assumeRole,
|
|
1289
|
-
resultsCacheTtl: value.resultsCacheTtl
|
|
1290
|
-
? toCdkDuration(value.resultsCacheTtl)
|
|
1291
|
-
: cdk.Duration.seconds(0),
|
|
1292
|
-
});
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
private addRoute(
|
|
1299
|
-
scope: Construct,
|
|
1300
|
-
routeKey: string,
|
|
1301
|
-
routeValue: ApiGatewayV1ApiRouteProps<keyof Authorizers>
|
|
1302
|
-
) {
|
|
1303
|
-
///////////////////
|
|
1304
|
-
// Normalize routeKey
|
|
1305
|
-
///////////////////
|
|
1306
|
-
routeKey = this.normalizeRouteKey(routeKey);
|
|
1307
|
-
if (this.functions[routeKey]) {
|
|
1308
|
-
throw new Error(`A route already exists for "${routeKey}"`);
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
///////////////////
|
|
1312
|
-
// Get path and method
|
|
1313
|
-
///////////////////
|
|
1314
|
-
const routeKeyParts = routeKey.split(" ");
|
|
1315
|
-
if (routeKeyParts.length !== 2) {
|
|
1316
|
-
throw new Error(`Invalid route ${routeKey}`);
|
|
1317
|
-
}
|
|
1318
|
-
const methodStr = routeKeyParts[0].toUpperCase();
|
|
1319
|
-
const path = routeKeyParts[1];
|
|
1320
|
-
const method = allowedMethods.find((per) => per === methodStr);
|
|
1321
|
-
if (!method) {
|
|
1322
|
-
throw new Error(`Invalid method defined for "${routeKey}"`);
|
|
1323
|
-
}
|
|
1324
|
-
if (path.length === 0) {
|
|
1325
|
-
throw new Error(`Invalid path defined for "${routeKey}"`);
|
|
1326
|
-
}
|
|
1327
|
-
const postfixName = `${methodStr}_${path}`;
|
|
1328
|
-
|
|
1329
|
-
///////////////////
|
|
1330
|
-
// Create Resources
|
|
1331
|
-
///////////////////
|
|
1332
|
-
let resource;
|
|
1333
|
-
if (path.endsWith("/{proxy+}")) {
|
|
1334
|
-
const parentResource = this.getResourceForPath(
|
|
1335
|
-
path.split("/").slice(0, -1).join("/")
|
|
1336
|
-
);
|
|
1337
|
-
resource = parentResource.addProxy({ anyMethod: false });
|
|
1338
|
-
} else {
|
|
1339
|
-
resource = this.getResourceForPath(path);
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
///////////////////
|
|
1343
|
-
// Create Method
|
|
1344
|
-
///////////////////
|
|
1345
|
-
const [routeProps, lambda] = (() => {
|
|
1346
|
-
if (Fn.isInlineDefinition(routeValue)) {
|
|
1347
|
-
const routeProps: ApiGatewayV1ApiFunctionRouteProps<keyof Authorizers> = {
|
|
1348
|
-
function: routeValue
|
|
1349
|
-
};
|
|
1350
|
-
return [
|
|
1351
|
-
routeProps,
|
|
1352
|
-
this.createFunction(scope, routeKey, routeProps, postfixName),
|
|
1353
|
-
];
|
|
1354
|
-
}
|
|
1355
|
-
else if (routeValue.cdk?.function) {
|
|
1356
|
-
return [
|
|
1357
|
-
routeValue,
|
|
1358
|
-
this.createCdkFunction(scope, routeKey, routeValue, postfixName),
|
|
1359
|
-
];
|
|
1360
|
-
}
|
|
1361
|
-
else {
|
|
1362
|
-
return [
|
|
1363
|
-
routeValue,
|
|
1364
|
-
this.createFunction(scope, routeKey, routeValue, postfixName),
|
|
1365
|
-
];
|
|
1366
|
-
}
|
|
1367
|
-
})();
|
|
1368
|
-
const integration = new apig.LambdaIntegration(
|
|
1369
|
-
lambda,
|
|
1370
|
-
routeProps.cdk?.integration
|
|
1371
|
-
);
|
|
1372
|
-
const methodOptions = this.buildRouteMethodOptions(routeProps);
|
|
1373
|
-
const apigMethod = resource.addMethod(method, integration, methodOptions);
|
|
1374
|
-
|
|
1375
|
-
///////////////////
|
|
1376
|
-
// Handle manually created Deployment resource (ie. imported REST API)
|
|
1377
|
-
///////////////////
|
|
1378
|
-
if (this._deployment) {
|
|
1379
|
-
this._deployment.addToLogicalId({ route: { routeKey, routeValue } });
|
|
1380
|
-
this._deployment.node.addDependency(apigMethod);
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
|
-
private createCdkFunction(
|
|
1385
|
-
scope: Construct,
|
|
1386
|
-
routeKey: string,
|
|
1387
|
-
routeProps: ApiGatewayV1ApiFunctionRouteProps<keyof Authorizers>,
|
|
1388
|
-
postfixName: string
|
|
1389
|
-
): lambda.IFunction {
|
|
1390
|
-
const lambda = routeProps.cdk?.function!;
|
|
1391
|
-
this.functions[routeKey] = lambda;
|
|
1392
|
-
return lambda;
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
private createFunction(
|
|
1396
|
-
scope: Construct,
|
|
1397
|
-
routeKey: string,
|
|
1398
|
-
routeProps: ApiGatewayV1ApiFunctionRouteProps<keyof Authorizers>,
|
|
1399
|
-
postfixName: string,
|
|
1400
|
-
): Fn {
|
|
1401
|
-
|
|
1402
|
-
const lambda = Fn.fromDefinition(
|
|
1403
|
-
scope,
|
|
1404
|
-
`Lambda_${postfixName}`,
|
|
1405
|
-
routeProps.function!,
|
|
1406
|
-
this.props.defaults?.function,
|
|
1407
|
-
`The "defaults.function" cannot be applied if an instance of a Function construct is passed in. Make sure to define all the routes using FunctionProps, so the ApiGatewayV1Api construct can apply the "defaults.function" to them.`
|
|
1408
|
-
);
|
|
1409
|
-
|
|
1410
|
-
// Add an environment variable to determine if the function is an Api route.
|
|
1411
|
-
// If it is, when "sst start" is not connected, we want to return an 500
|
|
1412
|
-
// status code and a descriptive error message.
|
|
1413
|
-
const root = scope.node.root as App;
|
|
1414
|
-
if (root.local) {
|
|
1415
|
-
lambda.addEnvironment("SST_DEBUG_IS_API_ROUTE", "1", {
|
|
1416
|
-
removeInEdge: true
|
|
1417
|
-
});
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
this.functions[routeKey] = lambda;
|
|
1421
|
-
|
|
1422
|
-
// attached existing permissions
|
|
1423
|
-
this.permissionsAttachedForAllRoutes.forEach((permissions) =>
|
|
1424
|
-
lambda.attachPermissions(permissions)
|
|
1425
|
-
);
|
|
1426
|
-
lambda.bind(this.bindingForAllRoutes);
|
|
1427
|
-
|
|
1428
|
-
return lambda;
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
private buildRouteMethodOptions(
|
|
1432
|
-
routeProps: ApiGatewayV1ApiFunctionRouteProps<keyof Authorizers>
|
|
1433
|
-
): apig.MethodOptions {
|
|
1434
|
-
const authorizerKey =
|
|
1435
|
-
routeProps.authorizer || this.props.defaults?.authorizer || "none";
|
|
1436
|
-
if (authorizerKey === "none") {
|
|
1437
|
-
return {
|
|
1438
|
-
authorizationType: apig.AuthorizationType.NONE,
|
|
1439
|
-
...routeProps.cdk?.method,
|
|
1440
|
-
};
|
|
1441
|
-
} else if (authorizerKey === "iam") {
|
|
1442
|
-
return {
|
|
1443
|
-
authorizationType: apig.AuthorizationType.IAM,
|
|
1444
|
-
...routeProps.cdk?.method,
|
|
1445
|
-
};
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
if (!this.props.authorizers || !this.props.authorizers[authorizerKey]) {
|
|
1449
|
-
throw new Error(`Cannot find authorizer "${authorizerKey.toString()}"`);
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
const authorizer = this.authorizersData[authorizerKey as string];
|
|
1453
|
-
const authorizationType = this.props.authorizers[authorizerKey].type;
|
|
1454
|
-
if (authorizationType === "user_pools") {
|
|
1455
|
-
return {
|
|
1456
|
-
authorizationType: apig.AuthorizationType.COGNITO,
|
|
1457
|
-
authorizer,
|
|
1458
|
-
authorizationScopes:
|
|
1459
|
-
routeProps.authorizationScopes ||
|
|
1460
|
-
this.props.defaults?.authorizationScopes,
|
|
1461
|
-
...routeProps.cdk?.method,
|
|
1462
|
-
};
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
return {
|
|
1466
|
-
authorizationType: apig.AuthorizationType.CUSTOM,
|
|
1467
|
-
authorizer,
|
|
1468
|
-
...routeProps.cdk?.method,
|
|
1469
|
-
};
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
private normalizeRouteKey(routeKey: string): string {
|
|
1473
|
-
return routeKey.split(/\s+/).join(" ");
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
private assertDomainNameIsLowerCase(domainName: string): void {
|
|
1477
|
-
if (domainName !== domainName.toLowerCase()) {
|
|
1478
|
-
throw new Error(`The domain name needs to be in lowercase`);
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
}
|