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
package/src/constructs/Api.ts
DELETED
|
@@ -1,1448 +0,0 @@
|
|
|
1
|
-
import { Construct } from "constructs";
|
|
2
|
-
import * as cdk from "aws-cdk-lib";
|
|
3
|
-
import * as cognito from "aws-cdk-lib/aws-cognito";
|
|
4
|
-
import * as acm from "aws-cdk-lib/aws-certificatemanager";
|
|
5
|
-
import * as cfnApig from "aws-cdk-lib/aws-apigatewayv2";
|
|
6
|
-
import * as apig from "@aws-cdk/aws-apigatewayv2-alpha";
|
|
7
|
-
import * as apigAuthorizers from "@aws-cdk/aws-apigatewayv2-authorizers-alpha";
|
|
8
|
-
import * as apigIntegrations from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
|
|
9
|
-
import * as elb from "aws-cdk-lib/aws-elasticloadbalancingv2";
|
|
10
|
-
import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
11
|
-
import * as logs from "aws-cdk-lib/aws-logs";
|
|
12
|
-
|
|
13
|
-
import { App } from "./App.js";
|
|
14
|
-
import { Stack } from "./Stack.js";
|
|
15
|
-
import { getFunctionRef, SSTConstruct, isCDKConstruct } from "./Construct.js";
|
|
16
|
-
import {
|
|
17
|
-
Function as Fn,
|
|
18
|
-
FunctionProps,
|
|
19
|
-
FunctionInlineDefinition,
|
|
20
|
-
FunctionDefinition,
|
|
21
|
-
} from "./Function.js";
|
|
22
|
-
import { Duration, toCdkDuration } from "./util/duration.js";
|
|
23
|
-
import { Permissions } from "./util/permission.js";
|
|
24
|
-
import * as apigV2Cors from "./util/apiGatewayV2Cors.js";
|
|
25
|
-
import * as apigV2Domain from "./util/apiGatewayV2Domain.js";
|
|
26
|
-
import * as apigV2AccessLog from "./util/apiGatewayV2AccessLog.js";
|
|
27
|
-
|
|
28
|
-
const PayloadFormatVersions = ["1.0", "2.0"] as const;
|
|
29
|
-
export type ApiPayloadFormatVersion = typeof PayloadFormatVersions[number];
|
|
30
|
-
type ApiHttpMethod = keyof typeof apig.HttpMethod;
|
|
31
|
-
|
|
32
|
-
/////////////////////
|
|
33
|
-
// Interfaces
|
|
34
|
-
/////////////////////
|
|
35
|
-
|
|
36
|
-
export type ApiAuthorizer =
|
|
37
|
-
| ApiUserPoolAuthorizer
|
|
38
|
-
| ApiJwtAuthorizer
|
|
39
|
-
| ApiLambdaAuthorizer;
|
|
40
|
-
|
|
41
|
-
interface ApiBaseAuthorizer {
|
|
42
|
-
/**
|
|
43
|
-
* The name of the authorizer.
|
|
44
|
-
*/
|
|
45
|
-
name?: string;
|
|
46
|
-
/**
|
|
47
|
-
* The identity source for which authorization is requested.
|
|
48
|
-
* @default `["$request.header.Authorization"]`
|
|
49
|
-
*/
|
|
50
|
-
identitySource?: string[];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Specify a user pool authorizer and configure additional options.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```js
|
|
58
|
-
* new Api(stack, "Api", {
|
|
59
|
-
* authorizers: {
|
|
60
|
-
* Authorizer: {
|
|
61
|
-
* type: "user_pool",
|
|
62
|
-
* userPool: {
|
|
63
|
-
* id: userPool.userPoolId,
|
|
64
|
-
* clientIds: [userPoolClient.userPoolClientId],
|
|
65
|
-
* },
|
|
66
|
-
* },
|
|
67
|
-
* },
|
|
68
|
-
* });
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export interface ApiUserPoolAuthorizer extends ApiBaseAuthorizer {
|
|
72
|
-
/**
|
|
73
|
-
* String li any shot and having even a miniscule shotteral to signify that the authorizer is user pool authorizer.
|
|
74
|
-
*/
|
|
75
|
-
type: "user_pool";
|
|
76
|
-
userPool?: {
|
|
77
|
-
/**
|
|
78
|
-
* The id of the user pool to use for authorization.
|
|
79
|
-
*/
|
|
80
|
-
id: string;
|
|
81
|
-
/**
|
|
82
|
-
* The ids of the user pool clients to use for authorization.
|
|
83
|
-
*/
|
|
84
|
-
clientIds?: string[];
|
|
85
|
-
/**
|
|
86
|
-
* The AWS region of the user pool.
|
|
87
|
-
*/
|
|
88
|
-
region?: string;
|
|
89
|
-
};
|
|
90
|
-
cdk?: {
|
|
91
|
-
/**
|
|
92
|
-
* This allows you to override the default settings this construct uses internally to create the authorizer.
|
|
93
|
-
*/
|
|
94
|
-
authorizer: apigAuthorizers.HttpUserPoolAuthorizer;
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Specify a JWT authorizer and configure additional options.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```js
|
|
103
|
-
* new Api(stack, "Api", {
|
|
104
|
-
* authorizers: {
|
|
105
|
-
* Authorizer: {
|
|
106
|
-
* type: "jwt",
|
|
107
|
-
* userPool: {
|
|
108
|
-
* issuer: "https://abc.us.auth0.com",
|
|
109
|
-
* audience: ["123"],
|
|
110
|
-
* },
|
|
111
|
-
* },
|
|
112
|
-
* },
|
|
113
|
-
* });
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
export interface ApiJwtAuthorizer extends ApiBaseAuthorizer {
|
|
117
|
-
/**
|
|
118
|
-
* String literal to signify that the authorizer is JWT authorizer.
|
|
119
|
-
*/
|
|
120
|
-
type: "jwt";
|
|
121
|
-
jwt?: {
|
|
122
|
-
/**
|
|
123
|
-
* The base domain of the identity provider that issues JWT.
|
|
124
|
-
*/
|
|
125
|
-
issuer: string;
|
|
126
|
-
/**
|
|
127
|
-
* A list of the intended recipients of the JWT.
|
|
128
|
-
*/
|
|
129
|
-
audience: string[];
|
|
130
|
-
};
|
|
131
|
-
cdk?: {
|
|
132
|
-
/**
|
|
133
|
-
* This allows you to override the default settings this construct uses internally to create the authorizer.
|
|
134
|
-
*/
|
|
135
|
-
authorizer: apigAuthorizers.HttpJwtAuthorizer;
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Specify a Lambda authorizer and configure additional options.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```js
|
|
144
|
-
* new Api(stack, "Api", {
|
|
145
|
-
* authorizers: {
|
|
146
|
-
* Authorizer: {
|
|
147
|
-
* type: "lambda",
|
|
148
|
-
* function: new Function(stack, "Authorizer", {
|
|
149
|
-
* handler: "test/lambda.handler",
|
|
150
|
-
* }),
|
|
151
|
-
* },
|
|
152
|
-
* },
|
|
153
|
-
* });
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
|
-
export interface ApiLambdaAuthorizer extends ApiBaseAuthorizer {
|
|
157
|
-
/**
|
|
158
|
-
* String literal to signify that the authorizer is Lambda authorizer.
|
|
159
|
-
*/
|
|
160
|
-
type: "lambda";
|
|
161
|
-
/**
|
|
162
|
-
* Used to create the authorizer function
|
|
163
|
-
*/
|
|
164
|
-
function?: Fn;
|
|
165
|
-
/**
|
|
166
|
-
* The types of responses the lambda can return.
|
|
167
|
-
*
|
|
168
|
-
* If `simple` is included then response format 2.0 will be used.
|
|
169
|
-
* @default ["iam"]
|
|
170
|
-
*/
|
|
171
|
-
responseTypes?: Lowercase<
|
|
172
|
-
keyof typeof apigAuthorizers.HttpLambdaResponseType
|
|
173
|
-
>[];
|
|
174
|
-
/**
|
|
175
|
-
* The amount of time the results are cached.
|
|
176
|
-
* @default Not cached
|
|
177
|
-
*/
|
|
178
|
-
resultsCacheTtl?: Duration;
|
|
179
|
-
cdk?: {
|
|
180
|
-
/**
|
|
181
|
-
* This allows you to override the default settings this construct uses internally to create the authorizer.
|
|
182
|
-
*/
|
|
183
|
-
authorizer: apigAuthorizers.HttpLambdaAuthorizer;
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export interface ApiCorsProps extends apigV2Cors.CorsProps {}
|
|
188
|
-
export interface ApiDomainProps extends apigV2Domain.CustomDomainProps {}
|
|
189
|
-
export interface ApiAccessLogProps extends apigV2AccessLog.AccessLogProps {}
|
|
190
|
-
|
|
191
|
-
export interface ApiProps<
|
|
192
|
-
Authorizers extends Record<string, ApiAuthorizer> = Record<
|
|
193
|
-
string,
|
|
194
|
-
ApiAuthorizer
|
|
195
|
-
>,
|
|
196
|
-
AuthorizerKeys = keyof Authorizers
|
|
197
|
-
> {
|
|
198
|
-
/**
|
|
199
|
-
* Define the routes for the API. Can be a function, proxy to another API, or point to an ALB
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
*
|
|
203
|
-
* ```js
|
|
204
|
-
* new Api(stack, "api", {
|
|
205
|
-
* routes: {
|
|
206
|
-
* "GET /notes" : "src/list.main",
|
|
207
|
-
* "GET /notes/{id}" : "src/get.main",
|
|
208
|
-
* "$default": "src/default.main"
|
|
209
|
-
* }
|
|
210
|
-
* })
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
routes?: Record<string, ApiRouteProps<AuthorizerKeys>>;
|
|
214
|
-
/**
|
|
215
|
-
* CORS support applied to all endpoints in this API
|
|
216
|
-
*
|
|
217
|
-
* @default true
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
*
|
|
221
|
-
* ```js
|
|
222
|
-
* new Api(stack, "Api", {
|
|
223
|
-
* cors: {
|
|
224
|
-
* allowMethods: ["GET"],
|
|
225
|
-
* },
|
|
226
|
-
* });
|
|
227
|
-
* ```
|
|
228
|
-
*
|
|
229
|
-
*/
|
|
230
|
-
cors?: boolean | ApiCorsProps;
|
|
231
|
-
/**
|
|
232
|
-
* Enable CloudWatch access logs for this API
|
|
233
|
-
*
|
|
234
|
-
* @default true
|
|
235
|
-
*
|
|
236
|
-
* @example
|
|
237
|
-
* ```js
|
|
238
|
-
* new Api(stack, "Api", {
|
|
239
|
-
* accessLog: true
|
|
240
|
-
* });
|
|
241
|
-
* ```
|
|
242
|
-
*
|
|
243
|
-
* ```js
|
|
244
|
-
* new Api(stack, "Api", {
|
|
245
|
-
* accessLog: {
|
|
246
|
-
* retention: "one_week",
|
|
247
|
-
* },
|
|
248
|
-
* });
|
|
249
|
-
* ```
|
|
250
|
-
*/
|
|
251
|
-
accessLog?: boolean | string | ApiAccessLogProps;
|
|
252
|
-
/**
|
|
253
|
-
* 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/)
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* ```js
|
|
257
|
-
* new Api(stack, "Api", {
|
|
258
|
-
* customDomain: "api.example.com"
|
|
259
|
-
* })
|
|
260
|
-
* ```
|
|
261
|
-
*
|
|
262
|
-
* ```js
|
|
263
|
-
* new Api(stack, "Api", {
|
|
264
|
-
* customDomain: {
|
|
265
|
-
* domainName: "api.example.com",
|
|
266
|
-
* hostedZone: "domain.com",
|
|
267
|
-
* path: "v1"
|
|
268
|
-
* }
|
|
269
|
-
* })
|
|
270
|
-
* ```
|
|
271
|
-
*/
|
|
272
|
-
customDomain?: string | ApiDomainProps;
|
|
273
|
-
/**
|
|
274
|
-
* Define the authorizers for the API. Can be a user pool, JWT, or Lambda authorizers.
|
|
275
|
-
*
|
|
276
|
-
* @example
|
|
277
|
-
* ```js
|
|
278
|
-
* new Api(stack, "Api", {
|
|
279
|
-
* authorizers: {
|
|
280
|
-
* Authorizer: {
|
|
281
|
-
* type: "user_pool",
|
|
282
|
-
* userPool: {
|
|
283
|
-
* id: userPool.userPoolId,
|
|
284
|
-
* clientIds: [userPoolClient.userPoolClientId],
|
|
285
|
-
* },
|
|
286
|
-
* },
|
|
287
|
-
* },
|
|
288
|
-
* });
|
|
289
|
-
* ```
|
|
290
|
-
*/
|
|
291
|
-
authorizers?: Authorizers;
|
|
292
|
-
defaults?: {
|
|
293
|
-
/**
|
|
294
|
-
* 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.
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
297
|
-
* ```js
|
|
298
|
-
* new Api(stack, "Api", {
|
|
299
|
-
* defaults: {
|
|
300
|
-
* function: {
|
|
301
|
-
* timeout: 20,
|
|
302
|
-
* environment: { tableName: table.tableName },
|
|
303
|
-
* permissions: [table],
|
|
304
|
-
* }
|
|
305
|
-
* }
|
|
306
|
-
* });
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
function?: FunctionProps;
|
|
310
|
-
/**
|
|
311
|
-
* The default authorizer for all the routes in the API.
|
|
312
|
-
*
|
|
313
|
-
* @example
|
|
314
|
-
* ```js
|
|
315
|
-
* new Api(stack, "Api", {
|
|
316
|
-
* defaults: {
|
|
317
|
-
* authorizer: "iam",
|
|
318
|
-
* }
|
|
319
|
-
* });
|
|
320
|
-
* ```
|
|
321
|
-
*
|
|
322
|
-
* @example
|
|
323
|
-
* ```js
|
|
324
|
-
* new Api(stack, "Api", {
|
|
325
|
-
* authorizers: {
|
|
326
|
-
* Authorizer: {
|
|
327
|
-
* type: "user_pool",
|
|
328
|
-
* userPool: {
|
|
329
|
-
* id: userPool.userPoolId,
|
|
330
|
-
* clientIds: [userPoolClient.userPoolClientId],
|
|
331
|
-
* },
|
|
332
|
-
* },
|
|
333
|
-
* },
|
|
334
|
-
* defaults: {
|
|
335
|
-
* authorizer: "Authorizer",
|
|
336
|
-
* }
|
|
337
|
-
* });
|
|
338
|
-
* ```
|
|
339
|
-
*/
|
|
340
|
-
authorizer?:
|
|
341
|
-
| "none"
|
|
342
|
-
| "iam"
|
|
343
|
-
| (string extends AuthorizerKeys
|
|
344
|
-
? Omit<AuthorizerKeys, "none" | "iam">
|
|
345
|
-
: AuthorizerKeys);
|
|
346
|
-
/**
|
|
347
|
-
* 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.
|
|
348
|
-
* @default []
|
|
349
|
-
*/
|
|
350
|
-
authorizationScopes?: string[];
|
|
351
|
-
/**
|
|
352
|
-
* The [payload format version](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html#http-api-develop-integrations-lambda.proxy-format) for all the endpoints in the API.
|
|
353
|
-
* @default "2.0"
|
|
354
|
-
*/
|
|
355
|
-
payloadFormatVersion?: ApiPayloadFormatVersion;
|
|
356
|
-
throttle?: {
|
|
357
|
-
/**
|
|
358
|
-
* The [burst rate](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-throttling.html) of the number of concurrent request for all the routes in the API.
|
|
359
|
-
*
|
|
360
|
-
* @example
|
|
361
|
-
* ```js
|
|
362
|
-
* new Api(stack, "Api", {
|
|
363
|
-
* defaults: {
|
|
364
|
-
* throttle: {
|
|
365
|
-
* burst: 100
|
|
366
|
-
* }
|
|
367
|
-
* }
|
|
368
|
-
* })
|
|
369
|
-
* ```
|
|
370
|
-
*/
|
|
371
|
-
burst?: number;
|
|
372
|
-
/**
|
|
373
|
-
* The [steady-state rate](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-throttling.html) of the number of concurrent request for all the routes in the API.
|
|
374
|
-
*
|
|
375
|
-
* @example
|
|
376
|
-
* ```js
|
|
377
|
-
* new Api(stack, "Api", {
|
|
378
|
-
* defaults: {
|
|
379
|
-
* throttle: {
|
|
380
|
-
* rate: 10
|
|
381
|
-
* }
|
|
382
|
-
* }
|
|
383
|
-
* })
|
|
384
|
-
* ```
|
|
385
|
-
*/
|
|
386
|
-
rate?: number;
|
|
387
|
-
};
|
|
388
|
-
};
|
|
389
|
-
cdk?: {
|
|
390
|
-
/**
|
|
391
|
-
* Allows you to override default id for this construct.
|
|
392
|
-
*/
|
|
393
|
-
id?: string;
|
|
394
|
-
/**
|
|
395
|
-
* Import the underlying HTTP API or override the default configuration
|
|
396
|
-
*
|
|
397
|
-
* @example
|
|
398
|
-
* ```js
|
|
399
|
-
* import { HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
|
|
400
|
-
*
|
|
401
|
-
* new Api(stack, "Api", {
|
|
402
|
-
* cdk: {
|
|
403
|
-
* httpApi: HttpApi.fromHttpApiAttributes(stack, "MyHttpApi", {
|
|
404
|
-
* httpApiId,
|
|
405
|
-
* }),
|
|
406
|
-
* }
|
|
407
|
-
* });
|
|
408
|
-
* ```
|
|
409
|
-
*/
|
|
410
|
-
httpApi?: apig.IHttpApi | apig.HttpApiProps;
|
|
411
|
-
/**
|
|
412
|
-
* Configures the stages to create for the HTTP API.
|
|
413
|
-
*
|
|
414
|
-
* Note that, a default stage is automatically created, unless the `cdk.httpApi.createDefaultStage` is set to `false.
|
|
415
|
-
*
|
|
416
|
-
* @example
|
|
417
|
-
* ```js
|
|
418
|
-
* import { HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
|
|
419
|
-
*
|
|
420
|
-
* new Api(stack, "Api", {
|
|
421
|
-
* cdk: {
|
|
422
|
-
* httpStages: [{
|
|
423
|
-
* stageName: "dev",
|
|
424
|
-
* autoDeploy: false,
|
|
425
|
-
* }],
|
|
426
|
-
* }
|
|
427
|
-
* });
|
|
428
|
-
* ```
|
|
429
|
-
*/
|
|
430
|
-
httpStages?: Omit<apig.HttpStageProps, "httpApi">[];
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
export type ApiRouteProps<AuthorizerKeys> =
|
|
435
|
-
| FunctionInlineDefinition
|
|
436
|
-
| ApiFunctionRouteProps<AuthorizerKeys>
|
|
437
|
-
| ApiHttpRouteProps<AuthorizerKeys>
|
|
438
|
-
| ApiAlbRouteProps<AuthorizerKeys>
|
|
439
|
-
| ApiPothosRouteProps<AuthorizerKeys>;
|
|
440
|
-
|
|
441
|
-
interface ApiBaseRouteProps<AuthorizerKeys = string> {
|
|
442
|
-
authorizer?:
|
|
443
|
-
| "none"
|
|
444
|
-
| "iam"
|
|
445
|
-
| (string extends AuthorizerKeys
|
|
446
|
-
? Omit<AuthorizerKeys, "none" | "iam">
|
|
447
|
-
: AuthorizerKeys);
|
|
448
|
-
authorizationScopes?: string[];
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Specify a function route handler and configure additional options
|
|
453
|
-
*
|
|
454
|
-
* @example
|
|
455
|
-
* ```js
|
|
456
|
-
* api.addRoutes(stack, {
|
|
457
|
-
* "GET /notes/{id}": {
|
|
458
|
-
* type: "function",
|
|
459
|
-
* function: "src/get.main",
|
|
460
|
-
* payloadFormatVersion: "1.0",
|
|
461
|
-
* }
|
|
462
|
-
* });
|
|
463
|
-
* ```
|
|
464
|
-
*/
|
|
465
|
-
export interface ApiFunctionRouteProps<AuthorizersKeys = string>
|
|
466
|
-
extends ApiBaseRouteProps<AuthorizersKeys> {
|
|
467
|
-
type?: "function";
|
|
468
|
-
/**
|
|
469
|
-
*The function definition used to create the function for this route.
|
|
470
|
-
*/
|
|
471
|
-
function?: FunctionDefinition;
|
|
472
|
-
/**
|
|
473
|
-
* The payload format version for the route.
|
|
474
|
-
*
|
|
475
|
-
* @default "2.0"
|
|
476
|
-
*/
|
|
477
|
-
payloadFormatVersion?: ApiPayloadFormatVersion;
|
|
478
|
-
cdk?: {
|
|
479
|
-
/**
|
|
480
|
-
* Use an existing Lambda function.
|
|
481
|
-
*/
|
|
482
|
-
function?: lambda.IFunction;
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* Specify a route handler that forwards to another URL
|
|
488
|
-
*
|
|
489
|
-
* @example
|
|
490
|
-
* ```js
|
|
491
|
-
* api.addRoutes(stack, {
|
|
492
|
-
* "GET /notes/{id}": {
|
|
493
|
-
* type: "url",
|
|
494
|
-
* url: "https://example.com/notes/{id}",
|
|
495
|
-
* }
|
|
496
|
-
* });
|
|
497
|
-
* ```
|
|
498
|
-
*/
|
|
499
|
-
export interface ApiHttpRouteProps<AuthorizersKeys>
|
|
500
|
-
extends ApiBaseRouteProps<AuthorizersKeys> {
|
|
501
|
-
/**
|
|
502
|
-
* This is a constant
|
|
503
|
-
*/
|
|
504
|
-
type: "url";
|
|
505
|
-
/**
|
|
506
|
-
* The URL to forward to
|
|
507
|
-
*/
|
|
508
|
-
url: string;
|
|
509
|
-
cdk?: {
|
|
510
|
-
/**
|
|
511
|
-
* Override the underlying CDK integration
|
|
512
|
-
*/
|
|
513
|
-
integration: apigIntegrations.HttpUrlIntegrationProps;
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Specify a route handler that forwards to an ALB
|
|
519
|
-
*
|
|
520
|
-
* @example
|
|
521
|
-
* ```js
|
|
522
|
-
* api.addRoutes(stack, {
|
|
523
|
-
* "GET /notes/{id}": {
|
|
524
|
-
* type: "alb",
|
|
525
|
-
* cdk: {
|
|
526
|
-
* albListener: listener,
|
|
527
|
-
* }
|
|
528
|
-
* }
|
|
529
|
-
* });
|
|
530
|
-
* ```
|
|
531
|
-
*/
|
|
532
|
-
export interface ApiAlbRouteProps<AuthorizersKeys>
|
|
533
|
-
extends ApiBaseRouteProps<AuthorizersKeys> {
|
|
534
|
-
type: "alb";
|
|
535
|
-
cdk: {
|
|
536
|
-
/**
|
|
537
|
-
* The listener to the application load balancer used for the integration.
|
|
538
|
-
*/
|
|
539
|
-
albListener: elb.IApplicationListener;
|
|
540
|
-
integration?: apigIntegrations.HttpAlbIntegrationProps;
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Specify a route handler that handles GraphQL queries using Pothos
|
|
546
|
-
*
|
|
547
|
-
* @example
|
|
548
|
-
* ```js
|
|
549
|
-
* api.addRoutes(stack, {
|
|
550
|
-
* "POST /graphql": {
|
|
551
|
-
* type: "pothos",
|
|
552
|
-
* schema: "backend/functions/graphql/schema.ts",
|
|
553
|
-
* output: "graphql/schema.graphql",
|
|
554
|
-
* function: {
|
|
555
|
-
* handler: "functions/graphql/graphql.ts",
|
|
556
|
-
* },
|
|
557
|
-
* commands: [
|
|
558
|
-
* "./genql graphql/graphql.schema graphql/
|
|
559
|
-
* ]
|
|
560
|
-
* }
|
|
561
|
-
* })
|
|
562
|
-
* ```
|
|
563
|
-
*/
|
|
564
|
-
export interface ApiPothosRouteProps<AuthorizerKeys>
|
|
565
|
-
extends ApiBaseRouteProps<AuthorizerKeys> {
|
|
566
|
-
type: "pothos";
|
|
567
|
-
/**
|
|
568
|
-
* The function definition used to create the function for this route. Must be a graphql handler
|
|
569
|
-
*/
|
|
570
|
-
function: FunctionDefinition;
|
|
571
|
-
/**
|
|
572
|
-
* Path to pothos schema
|
|
573
|
-
*/
|
|
574
|
-
schema?: string;
|
|
575
|
-
/**
|
|
576
|
-
* File to write graphql schema to
|
|
577
|
-
*/
|
|
578
|
-
output?: string;
|
|
579
|
-
/**
|
|
580
|
-
* Commands to run after generating schema. Useful for code generation steps
|
|
581
|
-
*/
|
|
582
|
-
commands?: string[];
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
/////////////////////
|
|
586
|
-
// Construct
|
|
587
|
-
/////////////////////
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* The Api construct is a higher level CDK construct that makes it easy to create an API.
|
|
591
|
-
*
|
|
592
|
-
* @example
|
|
593
|
-
*
|
|
594
|
-
* ```ts
|
|
595
|
-
* import { Api } from "@serverless-stack/resources";
|
|
596
|
-
*
|
|
597
|
-
* new Api(stack, "Api", {
|
|
598
|
-
* routes: {
|
|
599
|
-
* "GET /notes": "src/list.main",
|
|
600
|
-
* "POST /notes": "src/create.main",
|
|
601
|
-
* "GET /notes/{id}": "src/get.main",
|
|
602
|
-
* "PUT /notes/{id}": "src/update.main",
|
|
603
|
-
* "DELETE /notes/{id}": "src/delete.main",
|
|
604
|
-
* },
|
|
605
|
-
* });
|
|
606
|
-
* ```
|
|
607
|
-
*/
|
|
608
|
-
export class Api<
|
|
609
|
-
Authorizers extends Record<string, ApiAuthorizer> = Record<
|
|
610
|
-
string,
|
|
611
|
-
ApiAuthorizer
|
|
612
|
-
>
|
|
613
|
-
>
|
|
614
|
-
extends Construct
|
|
615
|
-
implements SSTConstruct
|
|
616
|
-
{
|
|
617
|
-
public readonly id: string;
|
|
618
|
-
public readonly cdk: {
|
|
619
|
-
/**
|
|
620
|
-
* The internally created CDK HttpApi instance.
|
|
621
|
-
*/
|
|
622
|
-
httpApi: apig.HttpApi;
|
|
623
|
-
/**
|
|
624
|
-
* If access logs are enabled, this is the internally created CDK LogGroup instance.
|
|
625
|
-
*/
|
|
626
|
-
accessLogGroup?: logs.LogGroup;
|
|
627
|
-
/**
|
|
628
|
-
* If custom domain is enabled, this is the internally created CDK DomainName instance.
|
|
629
|
-
*/
|
|
630
|
-
domainName?: apig.DomainName;
|
|
631
|
-
/**
|
|
632
|
-
* If custom domain is enabled, this is the internally created CDK Certificate instance.
|
|
633
|
-
*/
|
|
634
|
-
certificate?: acm.Certificate;
|
|
635
|
-
};
|
|
636
|
-
private props: ApiProps<Authorizers>;
|
|
637
|
-
private _customDomainUrl?: string;
|
|
638
|
-
private routesData: {
|
|
639
|
-
[key: string]:
|
|
640
|
-
| { type: "function"; function: Fn }
|
|
641
|
-
| { type: "lambda_function"; function: lambda.IFunction }
|
|
642
|
-
| ({ type: "pothos"; function: Fn } & Pick<
|
|
643
|
-
ApiPothosRouteProps<any>,
|
|
644
|
-
"schema" | "output" | "commands"
|
|
645
|
-
>)
|
|
646
|
-
| { type: "url"; url: string }
|
|
647
|
-
| { type: "alb"; alb: elb.IApplicationListener };
|
|
648
|
-
};
|
|
649
|
-
private authorizersData: Record<string, apig.IHttpRouteAuthorizer>;
|
|
650
|
-
private bindingForAllRoutes: SSTConstruct[] = [];
|
|
651
|
-
private permissionsAttachedForAllRoutes: Permissions[] = [];
|
|
652
|
-
|
|
653
|
-
constructor(scope: Construct, id: string, props?: ApiProps<Authorizers>) {
|
|
654
|
-
super(scope, props?.cdk?.id || id);
|
|
655
|
-
|
|
656
|
-
this.id = id;
|
|
657
|
-
this.props = props || {};
|
|
658
|
-
this.cdk = {} as any;
|
|
659
|
-
this.routesData = {};
|
|
660
|
-
this.authorizersData = {};
|
|
661
|
-
|
|
662
|
-
this.createHttpApi();
|
|
663
|
-
this.addAuthorizers(this.props.authorizers || ({} as Authorizers));
|
|
664
|
-
this.addRoutes(this, this.props.routes || {});
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
/**
|
|
668
|
-
* The AWS generated URL of the Api.
|
|
669
|
-
*/
|
|
670
|
-
public get url(): string {
|
|
671
|
-
const app = this.node.root as App;
|
|
672
|
-
return this.cdk.httpApi instanceof apig.HttpApi
|
|
673
|
-
? this.cdk.httpApi.apiEndpoint
|
|
674
|
-
: `https://${(this.cdk.httpApi as apig.IHttpApi).apiId}.execute-api.${
|
|
675
|
-
app.region
|
|
676
|
-
}.amazonaws.com`;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* If custom domain is enabled, this is the custom domain URL of the Api.
|
|
681
|
-
*
|
|
682
|
-
* :::note
|
|
683
|
-
* 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/`.
|
|
684
|
-
* :::
|
|
685
|
-
*/
|
|
686
|
-
public get customDomainUrl(): string | undefined {
|
|
687
|
-
return this._customDomainUrl;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
/**
|
|
691
|
-
* The routes for the Api
|
|
692
|
-
*/
|
|
693
|
-
public get routes(): string[] {
|
|
694
|
-
return Object.keys(this.routesData);
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
/**
|
|
698
|
-
* The ARN of the internally created API Gateway HTTP API
|
|
699
|
-
*/
|
|
700
|
-
public get httpApiArn(): string {
|
|
701
|
-
const stack = Stack.of(this);
|
|
702
|
-
return `arn:${stack.partition}:apigateway:${stack.region}::/apis/${this.cdk.httpApi.apiId}`;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* The id of the internally created API Gateway HTTP API
|
|
707
|
-
*/
|
|
708
|
-
public get httpApiId(): string {
|
|
709
|
-
return this.cdk.httpApi.apiId;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
/**
|
|
713
|
-
* Adds routes to the Api after it has been created.
|
|
714
|
-
*
|
|
715
|
-
* @example
|
|
716
|
-
* ```js
|
|
717
|
-
* api.addRoutes(stack, {
|
|
718
|
-
* "GET /notes/{id}": "src/get.main",
|
|
719
|
-
* "PUT /notes/{id}": "src/update.main",
|
|
720
|
-
* "DELETE /notes/{id}": "src/delete.main",
|
|
721
|
-
* });
|
|
722
|
-
* ```
|
|
723
|
-
*/
|
|
724
|
-
public addRoutes(
|
|
725
|
-
scope: Construct,
|
|
726
|
-
routes: Record<string, ApiRouteProps<keyof Authorizers>>
|
|
727
|
-
): void {
|
|
728
|
-
Object.keys(routes).forEach((routeKey: string) => {
|
|
729
|
-
this.addRoute(scope, routeKey, routes[routeKey]);
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
/**
|
|
734
|
-
* 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`.
|
|
735
|
-
*
|
|
736
|
-
* @example
|
|
737
|
-
* ```js
|
|
738
|
-
* const api = new Api(stack, "Api", {
|
|
739
|
-
* routes: {
|
|
740
|
-
* "GET /notes": "src/list.main",
|
|
741
|
-
* },
|
|
742
|
-
* });
|
|
743
|
-
*
|
|
744
|
-
* const listFunction = api.getFunction("GET /notes");
|
|
745
|
-
* ```
|
|
746
|
-
*/
|
|
747
|
-
public getFunction(routeKey: string): Fn | undefined {
|
|
748
|
-
const route = this.routesData[this.normalizeRouteKey(routeKey)];
|
|
749
|
-
if (!route) return;
|
|
750
|
-
if (route.type === "function" || route.type === "pothos") {
|
|
751
|
-
return route.function;
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
/**
|
|
756
|
-
* Binds the given list of resources to all the routes.
|
|
757
|
-
*
|
|
758
|
-
* @example
|
|
759
|
-
*
|
|
760
|
-
* ```js
|
|
761
|
-
* api.bind([STRIPE_KEY, bucket]);
|
|
762
|
-
* ```
|
|
763
|
-
*/
|
|
764
|
-
public bind(constructs: SSTConstruct[]) {
|
|
765
|
-
for (const route of Object.values(this.routesData)) {
|
|
766
|
-
if (route.type === "function" || route.type === "pothos") {
|
|
767
|
-
route.function.bind(constructs);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
this.bindingForAllRoutes.push(...constructs);
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
/**
|
|
774
|
-
* Binds the given list of resources to a specific route.
|
|
775
|
-
*
|
|
776
|
-
* @example
|
|
777
|
-
* ```js
|
|
778
|
-
* const api = new Api(stack, "Api", {
|
|
779
|
-
* routes: {
|
|
780
|
-
* "GET /notes": "src/list.main",
|
|
781
|
-
* },
|
|
782
|
-
* });
|
|
783
|
-
*
|
|
784
|
-
* api.bindToRoute("GET /notes", [STRIPE_KEY, bucket]);
|
|
785
|
-
* ```
|
|
786
|
-
*
|
|
787
|
-
*/
|
|
788
|
-
public bindToRoute(routeKey: string, constructs: SSTConstruct[]): void {
|
|
789
|
-
const fn = this.getFunction(routeKey);
|
|
790
|
-
if (!fn) {
|
|
791
|
-
throw new Error(
|
|
792
|
-
`Failed to bind resources. Route "${routeKey}" does not exist.`
|
|
793
|
-
);
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
fn.bind(constructs);
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
/**
|
|
800
|
-
* Attaches the given list of permissions to all the routes. This allows the functions to access other AWS resources.
|
|
801
|
-
*
|
|
802
|
-
* @example
|
|
803
|
-
*
|
|
804
|
-
* ```js
|
|
805
|
-
* api.attachPermissions(["s3"]);
|
|
806
|
-
* ```
|
|
807
|
-
*/
|
|
808
|
-
public attachPermissions(permissions: Permissions): void {
|
|
809
|
-
for (const route of Object.values(this.routesData)) {
|
|
810
|
-
if (route.type === "function" || route.type === "pothos") {
|
|
811
|
-
route.function.attachPermissions(permissions);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
this.permissionsAttachedForAllRoutes.push(permissions);
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
/**
|
|
818
|
-
* Attaches the given list of permissions to a specific route. This allows that function to access other AWS resources.
|
|
819
|
-
*
|
|
820
|
-
* @example
|
|
821
|
-
* ```js
|
|
822
|
-
* const api = new Api(stack, "Api", {
|
|
823
|
-
* routes: {
|
|
824
|
-
* "GET /notes": "src/list.main",
|
|
825
|
-
* },
|
|
826
|
-
* });
|
|
827
|
-
*
|
|
828
|
-
* api.attachPermissionsToRoute("GET /notes", ["s3"]);
|
|
829
|
-
* ```
|
|
830
|
-
*
|
|
831
|
-
*/
|
|
832
|
-
public attachPermissionsToRoute(
|
|
833
|
-
routeKey: string,
|
|
834
|
-
permissions: Permissions
|
|
835
|
-
): void {
|
|
836
|
-
const fn = this.getFunction(routeKey);
|
|
837
|
-
if (!fn) {
|
|
838
|
-
throw new Error(
|
|
839
|
-
`Failed to attach permissions. Route "${routeKey}" does not exist.`
|
|
840
|
-
);
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
fn.attachPermissions(permissions);
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
public getConstructMetadata() {
|
|
847
|
-
return {
|
|
848
|
-
type: "Api" as const,
|
|
849
|
-
data: {
|
|
850
|
-
graphql: false,
|
|
851
|
-
url: this.cdk.httpApi.url,
|
|
852
|
-
httpApiId: this.cdk.httpApi.apiId,
|
|
853
|
-
customDomainUrl: this._customDomainUrl,
|
|
854
|
-
routes: Object.entries(this.routesData).map(([key, data]) => {
|
|
855
|
-
if (data.type === "function")
|
|
856
|
-
return {
|
|
857
|
-
type: "function" as const,
|
|
858
|
-
route: key,
|
|
859
|
-
fn: getFunctionRef(data.function),
|
|
860
|
-
};
|
|
861
|
-
|
|
862
|
-
if (data.type === "pothos")
|
|
863
|
-
return {
|
|
864
|
-
type: "pothos" as const,
|
|
865
|
-
route: key,
|
|
866
|
-
fn: getFunctionRef(data.function),
|
|
867
|
-
schema: data.schema,
|
|
868
|
-
output: data.output,
|
|
869
|
-
commands: data.commands,
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
return { type: data.type, route: key };
|
|
873
|
-
}),
|
|
874
|
-
},
|
|
875
|
-
};
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
/** @internal */
|
|
879
|
-
public getFunctionBinding() {
|
|
880
|
-
return {
|
|
881
|
-
clientPackage: "api",
|
|
882
|
-
variables: {
|
|
883
|
-
url: {
|
|
884
|
-
environment: this.customDomainUrl || this.url,
|
|
885
|
-
parameter: this.customDomainUrl || this.url,
|
|
886
|
-
},
|
|
887
|
-
},
|
|
888
|
-
permissions: {},
|
|
889
|
-
};
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
private createHttpApi() {
|
|
893
|
-
const { cdk, cors, defaults, accessLog, customDomain } = this.props;
|
|
894
|
-
const id = this.node.id;
|
|
895
|
-
const app = this.node.root as App;
|
|
896
|
-
|
|
897
|
-
if (isCDKConstruct(cdk?.httpApi)) {
|
|
898
|
-
if (cors !== undefined) {
|
|
899
|
-
throw new Error(
|
|
900
|
-
`Cannot configure the "cors" when "cdk.httpApi" is a construct`
|
|
901
|
-
);
|
|
902
|
-
}
|
|
903
|
-
if (accessLog !== undefined) {
|
|
904
|
-
throw new Error(
|
|
905
|
-
`Cannot configure the "accessLog" when "cdk.httpApi" is a construct`
|
|
906
|
-
);
|
|
907
|
-
}
|
|
908
|
-
if (customDomain !== undefined) {
|
|
909
|
-
throw new Error(
|
|
910
|
-
`Cannot configure the "customDomain" when "cdk.httpApi" is a construct`
|
|
911
|
-
);
|
|
912
|
-
}
|
|
913
|
-
if (cdk?.httpStages !== undefined) {
|
|
914
|
-
throw new Error(
|
|
915
|
-
`Cannot configure the "stages" when "cdk.httpApi" is a construct`
|
|
916
|
-
);
|
|
917
|
-
}
|
|
918
|
-
this.cdk.httpApi = cdk?.httpApi as apig.HttpApi;
|
|
919
|
-
} else {
|
|
920
|
-
const httpApiProps = (cdk?.httpApi || {}) as apig.HttpApiProps;
|
|
921
|
-
|
|
922
|
-
// Validate input
|
|
923
|
-
if (httpApiProps.corsPreflight !== undefined) {
|
|
924
|
-
throw new Error(
|
|
925
|
-
`Cannot configure the "httpApi.corsPreflight" in the Api`
|
|
926
|
-
);
|
|
927
|
-
}
|
|
928
|
-
if (httpApiProps.defaultDomainMapping !== undefined) {
|
|
929
|
-
throw new Error(
|
|
930
|
-
`Cannot configure the "httpApi.defaultDomainMapping" in the Api`
|
|
931
|
-
);
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
// Handle Custom Domain
|
|
935
|
-
const customDomainData = apigV2Domain.buildCustomDomainData(
|
|
936
|
-
this,
|
|
937
|
-
customDomain
|
|
938
|
-
);
|
|
939
|
-
let defaultDomainMapping;
|
|
940
|
-
if (customDomainData) {
|
|
941
|
-
if (customDomainData.isApigDomainCreated) {
|
|
942
|
-
this.cdk.domainName = customDomainData.apigDomain as apig.DomainName;
|
|
943
|
-
}
|
|
944
|
-
if (customDomainData.isCertificatedCreated) {
|
|
945
|
-
this.cdk.certificate =
|
|
946
|
-
customDomainData.certificate as acm.Certificate;
|
|
947
|
-
}
|
|
948
|
-
defaultDomainMapping = {
|
|
949
|
-
domainName: customDomainData.apigDomain,
|
|
950
|
-
mappingKey: customDomainData.mappingKey,
|
|
951
|
-
};
|
|
952
|
-
this._customDomainUrl = `https://${customDomainData.url}`;
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
this.cdk.httpApi = new apig.HttpApi(this, "Api", {
|
|
956
|
-
apiName: app.logicalPrefixedName(id),
|
|
957
|
-
corsPreflight: apigV2Cors.buildCorsConfig(cors),
|
|
958
|
-
defaultDomainMapping,
|
|
959
|
-
...httpApiProps,
|
|
960
|
-
});
|
|
961
|
-
|
|
962
|
-
const httpStage = this.cdk.httpApi.defaultStage as apig.HttpStage;
|
|
963
|
-
|
|
964
|
-
// Configure throttling
|
|
965
|
-
if (defaults?.throttle?.burst && defaults?.throttle?.rate) {
|
|
966
|
-
const cfnStage = httpStage.node.defaultChild as cfnApig.CfnStage;
|
|
967
|
-
cfnStage.defaultRouteSettings = {
|
|
968
|
-
...(cfnStage.routeSettings || {}),
|
|
969
|
-
throttlingBurstLimit: defaults.throttle.burst,
|
|
970
|
-
throttlingRateLimit: defaults.throttle.rate,
|
|
971
|
-
};
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
// Configure access log
|
|
975
|
-
for (const def of cdk?.httpStages || []) {
|
|
976
|
-
const stage = new apig.HttpStage(this, "Stage" + def.stageName, {
|
|
977
|
-
...def,
|
|
978
|
-
httpApi: this.cdk.httpApi,
|
|
979
|
-
});
|
|
980
|
-
apigV2AccessLog.buildAccessLogData(this, accessLog, stage, false);
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
if (this.cdk.httpApi.defaultStage)
|
|
984
|
-
this.cdk.accessLogGroup = apigV2AccessLog.buildAccessLogData(
|
|
985
|
-
this,
|
|
986
|
-
accessLog,
|
|
987
|
-
this.cdk.httpApi.defaultStage as apig.HttpStage,
|
|
988
|
-
true
|
|
989
|
-
);
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
private addAuthorizers(authorizers: Authorizers) {
|
|
994
|
-
Object.entries(authorizers).forEach(([key, value]) => {
|
|
995
|
-
if (key === "none") {
|
|
996
|
-
throw new Error(`Cannot name an authorizer "none"`);
|
|
997
|
-
} else if (key === "iam") {
|
|
998
|
-
throw new Error(`Cannot name an authorizer "iam"`);
|
|
999
|
-
} else if (value.type === "user_pool") {
|
|
1000
|
-
if (value.cdk?.authorizer) {
|
|
1001
|
-
this.authorizersData[key] = value.cdk.authorizer;
|
|
1002
|
-
} else {
|
|
1003
|
-
if (!value.userPool) {
|
|
1004
|
-
throw new Error(`Missing "userPool" for "${key}" authorizer`);
|
|
1005
|
-
}
|
|
1006
|
-
const userPool = cognito.UserPool.fromUserPoolId(
|
|
1007
|
-
this,
|
|
1008
|
-
`Api-${this.node.id}-Authorizer-${key}-UserPool`,
|
|
1009
|
-
value.userPool.id
|
|
1010
|
-
);
|
|
1011
|
-
const userPoolClients =
|
|
1012
|
-
value.userPool.clientIds &&
|
|
1013
|
-
value.userPool.clientIds.map((clientId, i) =>
|
|
1014
|
-
cognito.UserPoolClient.fromUserPoolClientId(
|
|
1015
|
-
this,
|
|
1016
|
-
`Api-${this.node.id}-Authorizer-${key}-UserPoolClient-${i}`,
|
|
1017
|
-
clientId
|
|
1018
|
-
)
|
|
1019
|
-
);
|
|
1020
|
-
this.authorizersData[key] =
|
|
1021
|
-
new apigAuthorizers.HttpUserPoolAuthorizer(key, userPool, {
|
|
1022
|
-
authorizerName: value.name,
|
|
1023
|
-
identitySource: value.identitySource,
|
|
1024
|
-
userPoolClients,
|
|
1025
|
-
userPoolRegion: value.userPool.region,
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
|
-
} else if (value.type === "jwt") {
|
|
1029
|
-
if (value.cdk?.authorizer) {
|
|
1030
|
-
this.authorizersData[key] = value.cdk.authorizer;
|
|
1031
|
-
} else {
|
|
1032
|
-
if (!value.jwt) {
|
|
1033
|
-
throw new Error(`Missing "jwt" for "${key}" authorizer`);
|
|
1034
|
-
}
|
|
1035
|
-
this.authorizersData[key] = new apigAuthorizers.HttpJwtAuthorizer(
|
|
1036
|
-
key,
|
|
1037
|
-
value.jwt.issuer,
|
|
1038
|
-
{
|
|
1039
|
-
authorizerName: value.name,
|
|
1040
|
-
identitySource: value.identitySource,
|
|
1041
|
-
jwtAudience: value.jwt.audience,
|
|
1042
|
-
}
|
|
1043
|
-
);
|
|
1044
|
-
}
|
|
1045
|
-
} else if (value.type === "lambda") {
|
|
1046
|
-
if (value.cdk?.authorizer) {
|
|
1047
|
-
this.authorizersData[key] = value.cdk.authorizer;
|
|
1048
|
-
} else {
|
|
1049
|
-
if (!value.function) {
|
|
1050
|
-
throw new Error(`Missing "function" for "${key}" authorizer`);
|
|
1051
|
-
}
|
|
1052
|
-
this.authorizersData[key] = new apigAuthorizers.HttpLambdaAuthorizer(
|
|
1053
|
-
key,
|
|
1054
|
-
value.function,
|
|
1055
|
-
{
|
|
1056
|
-
authorizerName: value.name,
|
|
1057
|
-
identitySource: value.identitySource,
|
|
1058
|
-
responseTypes:
|
|
1059
|
-
value.responseTypes &&
|
|
1060
|
-
value.responseTypes.map(
|
|
1061
|
-
(type) =>
|
|
1062
|
-
apigAuthorizers.HttpLambdaResponseType[
|
|
1063
|
-
type.toUpperCase() as keyof typeof apigAuthorizers.HttpLambdaResponseType
|
|
1064
|
-
]
|
|
1065
|
-
),
|
|
1066
|
-
resultsCacheTtl: value.resultsCacheTtl
|
|
1067
|
-
? toCdkDuration(value.resultsCacheTtl)
|
|
1068
|
-
: cdk.Duration.seconds(0),
|
|
1069
|
-
}
|
|
1070
|
-
);
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
});
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
private addRoute(
|
|
1077
|
-
scope: Construct,
|
|
1078
|
-
routeKey: string,
|
|
1079
|
-
routeValue: ApiRouteProps<keyof Authorizers>
|
|
1080
|
-
): void {
|
|
1081
|
-
///////////////////
|
|
1082
|
-
// Normalize routeKey
|
|
1083
|
-
///////////////////
|
|
1084
|
-
routeKey = this.normalizeRouteKey(routeKey);
|
|
1085
|
-
if (this.routesData[routeKey]) {
|
|
1086
|
-
throw new Error(`A route already exists for "${routeKey}"`);
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
///////////////////
|
|
1090
|
-
// Get path and method
|
|
1091
|
-
///////////////////
|
|
1092
|
-
let postfixName;
|
|
1093
|
-
let httpRouteKey;
|
|
1094
|
-
let method: ApiHttpMethod;
|
|
1095
|
-
let path;
|
|
1096
|
-
if (routeKey === "$default") {
|
|
1097
|
-
postfixName = "default";
|
|
1098
|
-
httpRouteKey = apig.HttpRouteKey.DEFAULT;
|
|
1099
|
-
method = "ANY";
|
|
1100
|
-
path = routeKey;
|
|
1101
|
-
} else {
|
|
1102
|
-
const routeKeyParts = routeKey.split(" ");
|
|
1103
|
-
if (routeKeyParts.length !== 2) {
|
|
1104
|
-
throw new Error(`Invalid route ${routeKey}`);
|
|
1105
|
-
}
|
|
1106
|
-
method = routeKeyParts[0].toUpperCase() as ApiHttpMethod;
|
|
1107
|
-
if (!apig.HttpMethod[method]) {
|
|
1108
|
-
throw new Error(`Invalid method defined for "${routeKey}"`);
|
|
1109
|
-
}
|
|
1110
|
-
path = routeKeyParts[1];
|
|
1111
|
-
if (path.length === 0) {
|
|
1112
|
-
throw new Error(`Invalid path defined for "${routeKey}"`);
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
postfixName = `${method}_${path}`;
|
|
1116
|
-
httpRouteKey = apig.HttpRouteKey.with(path, apig.HttpMethod[method]);
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
///////////////////
|
|
1120
|
-
// Create route
|
|
1121
|
-
///////////////////
|
|
1122
|
-
const [routeProps, integration] = (() => {
|
|
1123
|
-
if (Fn.isInlineDefinition(routeValue)) {
|
|
1124
|
-
const routeProps: ApiFunctionRouteProps<keyof Authorizers> = {
|
|
1125
|
-
function: routeValue,
|
|
1126
|
-
};
|
|
1127
|
-
return [
|
|
1128
|
-
routeProps,
|
|
1129
|
-
this.createFunctionIntegration(
|
|
1130
|
-
scope,
|
|
1131
|
-
routeKey,
|
|
1132
|
-
routeProps,
|
|
1133
|
-
postfixName
|
|
1134
|
-
),
|
|
1135
|
-
];
|
|
1136
|
-
}
|
|
1137
|
-
if (routeValue.type === "alb") {
|
|
1138
|
-
return [
|
|
1139
|
-
routeValue,
|
|
1140
|
-
this.createAlbIntegration(scope, routeKey, routeValue, postfixName),
|
|
1141
|
-
];
|
|
1142
|
-
}
|
|
1143
|
-
if (routeValue.type === "url") {
|
|
1144
|
-
return [
|
|
1145
|
-
routeValue,
|
|
1146
|
-
this.createHttpIntegration(scope, routeKey, routeValue, postfixName),
|
|
1147
|
-
];
|
|
1148
|
-
}
|
|
1149
|
-
if (routeValue.type === "pothos") {
|
|
1150
|
-
return [
|
|
1151
|
-
routeValue,
|
|
1152
|
-
this.createPothosIntegration(
|
|
1153
|
-
scope,
|
|
1154
|
-
routeKey,
|
|
1155
|
-
routeValue,
|
|
1156
|
-
postfixName
|
|
1157
|
-
),
|
|
1158
|
-
];
|
|
1159
|
-
}
|
|
1160
|
-
if (routeValue.cdk?.function) {
|
|
1161
|
-
return [
|
|
1162
|
-
routeValue,
|
|
1163
|
-
this.createCdkFunctionIntegration(
|
|
1164
|
-
scope,
|
|
1165
|
-
routeKey,
|
|
1166
|
-
routeValue,
|
|
1167
|
-
postfixName
|
|
1168
|
-
),
|
|
1169
|
-
];
|
|
1170
|
-
}
|
|
1171
|
-
if ("function" in routeValue) {
|
|
1172
|
-
return [
|
|
1173
|
-
routeValue,
|
|
1174
|
-
this.createFunctionIntegration(
|
|
1175
|
-
scope,
|
|
1176
|
-
routeKey,
|
|
1177
|
-
routeValue,
|
|
1178
|
-
postfixName
|
|
1179
|
-
),
|
|
1180
|
-
];
|
|
1181
|
-
}
|
|
1182
|
-
if ("handler" in routeValue)
|
|
1183
|
-
throw new Error(
|
|
1184
|
-
`Function definition must be nested under the "function" key in the route props for "${routeKey}". ie. { function: { handler: "myfunc.handler" } }`
|
|
1185
|
-
);
|
|
1186
|
-
throw new Error(
|
|
1187
|
-
`Invalid route type for "${routeKey}". Must be one of: alb, url, function`
|
|
1188
|
-
);
|
|
1189
|
-
})();
|
|
1190
|
-
|
|
1191
|
-
const { authorizationType, authorizer, authorizationScopes } =
|
|
1192
|
-
this.buildRouteAuth(routeProps);
|
|
1193
|
-
const route = new apig.HttpRoute(scope, `Route_${postfixName}`, {
|
|
1194
|
-
httpApi: this.cdk.httpApi,
|
|
1195
|
-
routeKey: httpRouteKey,
|
|
1196
|
-
integration,
|
|
1197
|
-
authorizer,
|
|
1198
|
-
authorizationScopes,
|
|
1199
|
-
});
|
|
1200
|
-
|
|
1201
|
-
////////////////////
|
|
1202
|
-
// Configure route authorization type
|
|
1203
|
-
////////////////////
|
|
1204
|
-
// Note: we need to explicitly set `cfnRoute.authorizationType` to `NONE`
|
|
1205
|
-
// because if it were set to `AWS_IAM`, and then it is removed from
|
|
1206
|
-
// the CloudFormation template (ie. set to undefined), CloudFormation
|
|
1207
|
-
// doesn't updates the route. The route's authorizationType would still
|
|
1208
|
-
// be `AWS_IAM`.
|
|
1209
|
-
const cfnRoute = route.node.defaultChild! as cfnApig.CfnRoute;
|
|
1210
|
-
if (authorizationType === "iam") {
|
|
1211
|
-
cfnRoute.authorizationType = "AWS_IAM";
|
|
1212
|
-
} else if (authorizationType === "none") {
|
|
1213
|
-
cfnRoute.authorizationType = "NONE";
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
private createHttpIntegration(
|
|
1218
|
-
scope: Construct,
|
|
1219
|
-
routeKey: string,
|
|
1220
|
-
routeProps: ApiHttpRouteProps<keyof Authorizers>,
|
|
1221
|
-
postfixName: string
|
|
1222
|
-
): apig.HttpRouteIntegration {
|
|
1223
|
-
///////////////////
|
|
1224
|
-
// Create integration
|
|
1225
|
-
///////////////////
|
|
1226
|
-
const integration = new apigIntegrations.HttpUrlIntegration(
|
|
1227
|
-
`Integration_${postfixName}`,
|
|
1228
|
-
routeProps.url,
|
|
1229
|
-
routeProps.cdk?.integration
|
|
1230
|
-
);
|
|
1231
|
-
|
|
1232
|
-
// Store route
|
|
1233
|
-
this.routesData[routeKey] = {
|
|
1234
|
-
type: "url",
|
|
1235
|
-
url: routeProps.url,
|
|
1236
|
-
};
|
|
1237
|
-
|
|
1238
|
-
return integration;
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
private createAlbIntegration(
|
|
1242
|
-
scope: Construct,
|
|
1243
|
-
routeKey: string,
|
|
1244
|
-
routeProps: ApiAlbRouteProps<keyof Authorizers>,
|
|
1245
|
-
postfixName: string
|
|
1246
|
-
): apig.HttpRouteIntegration {
|
|
1247
|
-
///////////////////
|
|
1248
|
-
// Create integration
|
|
1249
|
-
///////////////////
|
|
1250
|
-
const integration = new apigIntegrations.HttpAlbIntegration(
|
|
1251
|
-
`Integration_${postfixName}`,
|
|
1252
|
-
routeProps.cdk?.albListener!,
|
|
1253
|
-
routeProps.cdk?.integration
|
|
1254
|
-
);
|
|
1255
|
-
|
|
1256
|
-
// Store route
|
|
1257
|
-
this.routesData[routeKey] = {
|
|
1258
|
-
type: "alb",
|
|
1259
|
-
alb: routeProps.cdk?.albListener!,
|
|
1260
|
-
};
|
|
1261
|
-
|
|
1262
|
-
return integration;
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
protected createPothosIntegration(
|
|
1266
|
-
scope: Construct,
|
|
1267
|
-
routeKey: string,
|
|
1268
|
-
routeProps: ApiPothosRouteProps<keyof Authorizers>,
|
|
1269
|
-
postfixName: string
|
|
1270
|
-
): apig.HttpRouteIntegration {
|
|
1271
|
-
const result = this.createFunctionIntegration(
|
|
1272
|
-
scope,
|
|
1273
|
-
routeKey,
|
|
1274
|
-
{
|
|
1275
|
-
...routeProps,
|
|
1276
|
-
type: "function",
|
|
1277
|
-
payloadFormatVersion: "2.0",
|
|
1278
|
-
},
|
|
1279
|
-
postfixName
|
|
1280
|
-
);
|
|
1281
|
-
const data = this.routesData[routeKey];
|
|
1282
|
-
if (data.type === "function") {
|
|
1283
|
-
this.routesData[routeKey] = {
|
|
1284
|
-
...data,
|
|
1285
|
-
type: "pothos",
|
|
1286
|
-
output: routeProps.output,
|
|
1287
|
-
schema: routeProps.schema,
|
|
1288
|
-
commands: routeProps.commands,
|
|
1289
|
-
};
|
|
1290
|
-
}
|
|
1291
|
-
return result;
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
protected createCdkFunctionIntegration(
|
|
1295
|
-
scope: Construct,
|
|
1296
|
-
routeKey: string,
|
|
1297
|
-
routeProps: ApiFunctionRouteProps<keyof Authorizers>,
|
|
1298
|
-
postfixName: string
|
|
1299
|
-
): apig.HttpRouteIntegration {
|
|
1300
|
-
///////////////////
|
|
1301
|
-
// Get payload format
|
|
1302
|
-
///////////////////
|
|
1303
|
-
const payloadFormatVersion: ApiPayloadFormatVersion =
|
|
1304
|
-
routeProps.payloadFormatVersion ||
|
|
1305
|
-
this.props.defaults?.payloadFormatVersion ||
|
|
1306
|
-
"2.0";
|
|
1307
|
-
if (!PayloadFormatVersions.includes(payloadFormatVersion)) {
|
|
1308
|
-
throw new Error(
|
|
1309
|
-
`PayloadFormatVersion: sst.Api does not currently support ${payloadFormatVersion} payload format version. Only "V1" and "V2" are currently supported.`
|
|
1310
|
-
);
|
|
1311
|
-
}
|
|
1312
|
-
const integrationPayloadFormatVersion =
|
|
1313
|
-
payloadFormatVersion === "1.0"
|
|
1314
|
-
? apig.PayloadFormatVersion.VERSION_1_0
|
|
1315
|
-
: apig.PayloadFormatVersion.VERSION_2_0;
|
|
1316
|
-
|
|
1317
|
-
///////////////////
|
|
1318
|
-
// Create Function
|
|
1319
|
-
///////////////////
|
|
1320
|
-
const lambda = routeProps.cdk?.function!;
|
|
1321
|
-
|
|
1322
|
-
///////////////////
|
|
1323
|
-
// Create integration
|
|
1324
|
-
///////////////////
|
|
1325
|
-
const integration = new apigIntegrations.HttpLambdaIntegration(
|
|
1326
|
-
`Integration_${postfixName}`,
|
|
1327
|
-
lambda,
|
|
1328
|
-
{
|
|
1329
|
-
payloadFormatVersion: integrationPayloadFormatVersion,
|
|
1330
|
-
}
|
|
1331
|
-
);
|
|
1332
|
-
|
|
1333
|
-
// Store route
|
|
1334
|
-
this.routesData[routeKey] = {
|
|
1335
|
-
type: "lambda_function",
|
|
1336
|
-
function: lambda,
|
|
1337
|
-
};
|
|
1338
|
-
|
|
1339
|
-
return integration;
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
protected createFunctionIntegration(
|
|
1343
|
-
scope: Construct,
|
|
1344
|
-
routeKey: string,
|
|
1345
|
-
routeProps: ApiFunctionRouteProps<keyof Authorizers>,
|
|
1346
|
-
postfixName: string
|
|
1347
|
-
): apig.HttpRouteIntegration {
|
|
1348
|
-
///////////////////
|
|
1349
|
-
// Get payload format
|
|
1350
|
-
///////////////////
|
|
1351
|
-
const payloadFormatVersion: ApiPayloadFormatVersion =
|
|
1352
|
-
routeProps.payloadFormatVersion ||
|
|
1353
|
-
this.props.defaults?.payloadFormatVersion ||
|
|
1354
|
-
"2.0";
|
|
1355
|
-
if (!PayloadFormatVersions.includes(payloadFormatVersion)) {
|
|
1356
|
-
throw new Error(
|
|
1357
|
-
`PayloadFormatVersion: sst.Api does not currently support ${payloadFormatVersion} payload format version. Only "V1" and "V2" are currently supported.`
|
|
1358
|
-
);
|
|
1359
|
-
}
|
|
1360
|
-
const integrationPayloadFormatVersion =
|
|
1361
|
-
payloadFormatVersion === "1.0"
|
|
1362
|
-
? apig.PayloadFormatVersion.VERSION_1_0
|
|
1363
|
-
: apig.PayloadFormatVersion.VERSION_2_0;
|
|
1364
|
-
|
|
1365
|
-
///////////////////
|
|
1366
|
-
// Create Function
|
|
1367
|
-
///////////////////
|
|
1368
|
-
const lambda = Fn.fromDefinition(
|
|
1369
|
-
scope,
|
|
1370
|
-
`Lambda_${postfixName}`,
|
|
1371
|
-
routeProps.function!,
|
|
1372
|
-
this.props.defaults?.function,
|
|
1373
|
-
`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 Api construct can apply the "defaults.function" to them.`
|
|
1374
|
-
);
|
|
1375
|
-
// Add an environment variable to determine if the function is an Api route.
|
|
1376
|
-
// If it is, when "sst start" is not connected, we want to return an 500
|
|
1377
|
-
// status code and a descriptive error message.
|
|
1378
|
-
const root = scope.node.root as App;
|
|
1379
|
-
if (root.local) {
|
|
1380
|
-
lambda.addEnvironment("SST_DEBUG_IS_API_ROUTE", "1", {
|
|
1381
|
-
removeInEdge: true,
|
|
1382
|
-
});
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
///////////////////
|
|
1386
|
-
// Create integration
|
|
1387
|
-
///////////////////
|
|
1388
|
-
const integration = new apigIntegrations.HttpLambdaIntegration(
|
|
1389
|
-
`Integration_${postfixName}`,
|
|
1390
|
-
lambda,
|
|
1391
|
-
{
|
|
1392
|
-
payloadFormatVersion: integrationPayloadFormatVersion,
|
|
1393
|
-
}
|
|
1394
|
-
);
|
|
1395
|
-
|
|
1396
|
-
// Store route
|
|
1397
|
-
this.routesData[routeKey] = {
|
|
1398
|
-
type: "function",
|
|
1399
|
-
function: lambda,
|
|
1400
|
-
};
|
|
1401
|
-
|
|
1402
|
-
// Attached existing permissions
|
|
1403
|
-
this.permissionsAttachedForAllRoutes.forEach((permissions) =>
|
|
1404
|
-
lambda.attachPermissions(permissions)
|
|
1405
|
-
);
|
|
1406
|
-
lambda.bind(this.bindingForAllRoutes);
|
|
1407
|
-
|
|
1408
|
-
return integration;
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
private buildRouteAuth(routeProps: ApiBaseRouteProps<keyof Authorizers>) {
|
|
1412
|
-
const authorizerKey =
|
|
1413
|
-
routeProps?.authorizer || this.props.defaults?.authorizer || "none";
|
|
1414
|
-
if (authorizerKey === "none") {
|
|
1415
|
-
return {
|
|
1416
|
-
authorizationType: "none",
|
|
1417
|
-
authorizer: new apig.HttpNoneAuthorizer(),
|
|
1418
|
-
};
|
|
1419
|
-
} else if (authorizerKey === "iam") {
|
|
1420
|
-
return {
|
|
1421
|
-
authorizationType: "iam",
|
|
1422
|
-
authorizer: new apigAuthorizers.HttpIamAuthorizer(),
|
|
1423
|
-
};
|
|
1424
|
-
}
|
|
1425
|
-
|
|
1426
|
-
if (
|
|
1427
|
-
!this.props.authorizers ||
|
|
1428
|
-
!this.props.authorizers[authorizerKey as string]
|
|
1429
|
-
) {
|
|
1430
|
-
throw new Error(`Cannot find authorizer "${authorizerKey.toString()}"`);
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
const authorizer = this.authorizersData[authorizerKey as string];
|
|
1434
|
-
const authorizationType =
|
|
1435
|
-
this.props.authorizers[authorizerKey as string].type;
|
|
1436
|
-
const authorizationScopes =
|
|
1437
|
-
authorizationType === "jwt" || authorizationType === "user_pool"
|
|
1438
|
-
? routeProps?.authorizationScopes ||
|
|
1439
|
-
this.props.defaults?.authorizationScopes
|
|
1440
|
-
: undefined;
|
|
1441
|
-
|
|
1442
|
-
return { authorizationType, authorizer, authorizationScopes };
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
private normalizeRouteKey(routeKey: string): string {
|
|
1446
|
-
return routeKey.split(/\s+/).join(" ");
|
|
1447
|
-
}
|
|
1448
|
-
}
|