@webiny/project-aws 6.6.0-alpha.11 → 6.6.0-alpha.13
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/_templates/appTemplates/api/graphql/package.json +2 -2
- package/_templates/appTemplates/api/graphql/src/index.ts +2 -2
- package/_templates/appTemplates/api/graphql/src/web.ts +15 -0
- package/_templates/appTemplates/api/graphql/webiny.config.ts +6 -1
- package/_templates/extensions/OpenSearch/api/graphql/src/index.ts +2 -2
- package/_templates/extensions/OpenSearch/api/graphql/src/web.ts +15 -0
- package/_templates/extensions/Postgres/api/graphql/src/index.ts +17 -0
- package/_templates/extensions/Postgres/api/graphql/src/web.ts +15 -0
- package/api.d.ts +6 -6
- package/api.js +3 -2
- package/api.js.map +1 -1
- package/apps/createApiApp.d.ts +18 -1
- package/apps/createCoreApp.d.ts +1 -1
- package/decorators/GetPulumiServiceWithDownloadInfo.d.ts +1 -3
- package/decorators/GetPulumiServiceWithDownloadInfo.js +15 -11
- package/decorators/GetPulumiServiceWithDownloadInfo.js.map +1 -1
- package/extensions/ApiRoute.d.ts +2 -1
- package/extensions/ApiRoute.js.map +1 -1
- package/extensions/AuroraPostgresCluster.d.ts +12 -0
- package/extensions/AuroraPostgresCluster.js +30 -0
- package/extensions/AuroraPostgresCluster.js.map +1 -0
- package/extensions/Postgres/AddCorePostgres.d.ts +27 -0
- package/extensions/Postgres/AddCorePostgres.js +52 -0
- package/extensions/Postgres/AddCorePostgres.js.map +1 -0
- package/extensions/Postgres/CopyPgModulesAfterApiBuild.d.ts +16 -0
- package/extensions/Postgres/CopyPgModulesAfterApiBuild.js +42 -0
- package/extensions/Postgres/CopyPgModulesAfterApiBuild.js.map +1 -0
- package/extensions/Postgres/ReplaceApiLambdaFnHandlers.d.ts +17 -0
- package/extensions/Postgres/ReplaceApiLambdaFnHandlers.js +33 -0
- package/extensions/Postgres/ReplaceApiLambdaFnHandlers.js.map +1 -0
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.d.ts +23 -0
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.js +41 -0
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.js.map +1 -0
- package/extensions/Postgres/copyPgRuntimeModules.d.ts +27 -0
- package/extensions/Postgres/copyPgRuntimeModules.js +124 -0
- package/extensions/Postgres/copyPgRuntimeModules.js.map +1 -0
- package/extensions/Postgres/rds-ca-bundle.pem +2888 -0
- package/extensions/Postgres/rdsCaBundle.d.ts +13 -0
- package/extensions/Postgres/rdsCaBundle.js +7 -0
- package/extensions/Postgres/rdsCaBundle.js.map +1 -0
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.d.ts +20 -0
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.js +34 -0
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.js.map +1 -0
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.d.ts +20 -0
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.js +27 -0
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.js.map +1 -0
- package/extensions/ProjectAws.js +4 -0
- package/extensions/ProjectAws.js.map +1 -1
- package/extensions/definitions.js +3 -1
- package/extensions/definitions.js.map +1 -1
- package/extensions/index.d.ts +4 -1
- package/extensions/index.js +3 -2
- package/extensions/registerExtensionImplementations.js +3 -1
- package/extensions/registerExtensionImplementations.js.map +1 -1
- package/extensions/toCloudFrontPathPattern.d.ts +5 -0
- package/extensions/toCloudFrontPathPattern.js +8 -0
- package/extensions/toCloudFrontPathPattern.js.map +1 -0
- package/features/Watch/AwsWatch.js +1 -0
- package/features/Watch/AwsWatch.js.map +1 -1
- package/features/Watch/forwarder/createForwarderZip.d.ts +8 -0
- package/features/Watch/forwarder/createForwarderZip.js +19 -0
- package/features/Watch/forwarder/createForwarderZip.js.map +1 -0
- package/features/Watch/forwarder/lambdaHandler.cjs +124 -0
- package/features/Watch/forwarder/lambdaHandler.d.cts +1 -0
- package/features/Watch/forwarder/mqtt.cjs +4 -0
- package/features/Watch/forwarder/mqtt.d.cts +1 -0
- package/features/Watch/forwarder/webHandler.d.mts +1 -0
- package/features/Watch/forwarder/webHandler.mjs +298 -0
- package/features/Watch/replaceLambdaFunctions.d.ts +2 -0
- package/features/Watch/replaceLambdaFunctions.js +44 -3
- package/features/Watch/replaceLambdaFunctions.js.map +1 -1
- package/features/Watch/replaceWebFunction.d.ts +44 -0
- package/features/Watch/replaceWebFunction.js +119 -0
- package/features/Watch/replaceWebFunction.js.map +1 -0
- package/infra.d.ts +13 -0
- package/infra.js +8 -6
- package/infra.js.map +1 -1
- package/package.json +21 -17
- package/project.d.ts +1 -0
- package/pulumi/apps/admin/createAdminPulumiApp.js +1 -2
- package/pulumi/apps/admin/createAdminPulumiApp.js.map +1 -1
- package/pulumi/apps/api/ApiCloudfront.d.ts +5 -0
- package/pulumi/apps/api/ApiCloudfront.js +71 -198
- package/pulumi/apps/api/ApiCloudfront.js.map +1 -1
- package/pulumi/apps/api/ApiFileManager.d.ts +8 -1
- package/pulumi/apps/api/ApiFileManager.js +11 -1
- package/pulumi/apps/api/ApiFileManager.js.map +1 -1
- package/pulumi/apps/api/ApiGraphql.d.ts +1 -1
- package/pulumi/apps/api/ApiGraphql.js +78 -69
- package/pulumi/apps/api/ApiGraphql.js.map +1 -1
- package/pulumi/apps/api/ApiGraphqlWeb.d.ts +45 -0
- package/pulumi/apps/api/ApiGraphqlWeb.js +280 -0
- package/pulumi/apps/api/ApiGraphqlWeb.js.map +1 -0
- package/pulumi/apps/api/ApiOutput.d.ts +1 -0
- package/pulumi/apps/api/ApiOutput.js +2 -1
- package/pulumi/apps/api/ApiOutput.js.map +1 -1
- package/pulumi/apps/api/ApiSchemaSetup.d.ts +86 -0
- package/pulumi/apps/api/ApiSchemaSetup.js +139 -0
- package/pulumi/apps/api/ApiSchemaSetup.js.map +1 -0
- package/pulumi/apps/api/apiDynamoDb.d.ts +6 -0
- package/pulumi/apps/api/apiDynamoDb.js +20 -0
- package/pulumi/apps/api/apiDynamoDb.js.map +1 -0
- package/pulumi/apps/api/apiServiceManifests.d.ts +24 -0
- package/pulumi/apps/api/apiServiceManifests.js +27 -0
- package/pulumi/apps/api/apiServiceManifests.js.map +1 -0
- package/pulumi/apps/api/backgroundTask/types.js.map +1 -1
- package/pulumi/apps/api/cloudfront/addWebRouteBehavior.d.ts +8 -0
- package/pulumi/apps/api/cloudfront/addWebRouteBehavior.js +26 -0
- package/pulumi/apps/api/cloudfront/addWebRouteBehavior.js.map +1 -0
- package/pulumi/apps/api/cloudfront/allowFunctionUrlInvoke.d.ts +17 -0
- package/pulumi/apps/api/cloudfront/allowFunctionUrlInvoke.js +27 -0
- package/pulumi/apps/api/cloudfront/allowFunctionUrlInvoke.js.map +1 -0
- package/pulumi/apps/api/cloudfront/allowWebFunctionInvoke.d.ts +8 -0
- package/pulumi/apps/api/cloudfront/allowWebFunctionInvoke.js +31 -0
- package/pulumi/apps/api/cloudfront/allowWebFunctionInvoke.js.map +1 -0
- package/pulumi/apps/api/cloudfront/constants.d.ts +24 -0
- package/pulumi/apps/api/cloudfront/constants.js +43 -0
- package/pulumi/apps/api/cloudfront/constants.js.map +1 -0
- package/pulumi/apps/api/cloudfront/createFilesRouting.d.ts +10 -0
- package/pulumi/apps/api/cloudfront/createFilesRouting.js +35 -0
- package/pulumi/apps/api/cloudfront/createFilesRouting.js.map +1 -0
- package/pulumi/apps/api/cloudfront/createGatewayRouting.d.ts +10 -0
- package/pulumi/apps/api/cloudfront/createGatewayRouting.js +48 -0
- package/pulumi/apps/api/cloudfront/createGatewayRouting.js.map +1 -0
- package/pulumi/apps/api/cloudfront/createStreamRouting.d.ts +10 -0
- package/pulumi/apps/api/cloudfront/createStreamRouting.js +87 -0
- package/pulumi/apps/api/cloudfront/createStreamRouting.js.map +1 -0
- package/pulumi/apps/api/cloudfront/createWebRouting.d.ts +13 -0
- package/pulumi/apps/api/cloudfront/createWebRouting.js +140 -0
- package/pulumi/apps/api/cloudfront/createWebRouting.js.map +1 -0
- package/pulumi/apps/api/createApiPulumiApp.d.ts +22 -4
- package/pulumi/apps/api/createApiPulumiApp.js +122 -81
- package/pulumi/apps/api/createApiPulumiApp.js.map +1 -1
- package/pulumi/apps/api/index.d.ts +2 -0
- package/pulumi/apps/api/index.js +2 -0
- package/pulumi/apps/api/isRouteNameAllowed.d.ts +7 -0
- package/pulumi/apps/api/isRouteNameAllowed.js +6 -0
- package/pulumi/apps/api/isRouteNameAllowed.js.map +1 -0
- package/pulumi/apps/common/CoreOutput.d.ts +13 -0
- package/pulumi/apps/common/CoreOutput.js +17 -2
- package/pulumi/apps/common/CoreOutput.js.map +1 -1
- package/pulumi/apps/core/CoreCognito.d.ts +14 -0
- package/pulumi/apps/core/CoreCognito.js +34 -1
- package/pulumi/apps/core/CoreCognito.js.map +1 -1
- package/pulumi/apps/core/CoreOpenSearch.js +12 -6
- package/pulumi/apps/core/CoreOpenSearch.js.map +1 -1
- package/pulumi/apps/core/CorePostgres.d.ts +48 -0
- package/pulumi/apps/core/CorePostgres.js +262 -0
- package/pulumi/apps/core/CorePostgres.js.map +1 -0
- package/pulumi/apps/core/cognitoIdentityProviders/configure.js +11 -0
- package/pulumi/apps/core/cognitoIdentityProviders/configure.js.map +1 -1
- package/pulumi/apps/core/coreDynamoDb.d.ts +19 -0
- package/pulumi/apps/core/coreDynamoDb.js +34 -0
- package/pulumi/apps/core/coreDynamoDb.js.map +1 -0
- package/pulumi/apps/core/coreServiceManifests.d.ts +31 -0
- package/pulumi/apps/core/coreServiceManifests.js +31 -0
- package/pulumi/apps/core/coreServiceManifests.js.map +1 -0
- package/pulumi/apps/core/coreVpcEndpoints.d.ts +14 -0
- package/pulumi/apps/core/coreVpcEndpoints.js +55 -0
- package/pulumi/apps/core/coreVpcEndpoints.js.map +1 -0
- package/pulumi/apps/core/createCorePulumiApp.d.ts +1 -1
- package/pulumi/apps/core/createCorePulumiApp.js +18 -78
- package/pulumi/apps/core/createCorePulumiApp.js.map +1 -1
- package/pulumi/apps/core/index.d.ts +1 -0
- package/pulumi/apps/core/index.js +1 -0
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.d.ts +15 -0
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.js +16 -0
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.js.map +1 -0
- package/pulumi/apps/extensions/getVpcConfigFromExtension.d.ts +4 -0
- package/pulumi/apps/extensions/isWebFunctionEnabled.d.ts +5 -0
- package/pulumi/apps/extensions/isWebFunctionEnabled.js +9 -0
- package/pulumi/apps/extensions/isWebFunctionEnabled.js.map +1 -0
- package/pulumi/apps/extensions/projectUsesPostgres.d.ts +2 -0
- package/pulumi/apps/extensions/projectUsesPostgres.js +10 -0
- package/pulumi/apps/extensions/projectUsesPostgres.js.map +1 -0
- package/pulumi/apps/react/adminSettingsItem.d.ts +17 -0
- package/pulumi/apps/react/adminSettingsItem.js +28 -0
- package/pulumi/apps/react/adminSettingsItem.js.map +1 -0
- package/pulumi/apps/react/createReactPulumiApp.js +6 -19
- package/pulumi/apps/react/createReactPulumiApp.js.map +1 -1
- package/pulumi/extensions/index.d.ts +12 -45
- package/pulumi/extensions/index.js +2 -1
- package/pulumi/extensions/index.js.map +1 -1
- package/pulumi/types.d.ts +5 -0
- package/pulumi/utils/lambdaEnvVariables.js +2 -2
- package/pulumi/utils/lambdaEnvVariables.js.map +1 -1
- package/pulumi/utils/tagResources.js +2 -0
- package/pulumi/utils/tagResources.js.map +1 -1
- package/pulumi/utils/withServiceManifest.d.ts +35 -1
- package/pulumi/utils/withServiceManifest.js +53 -9
- package/pulumi/utils/withServiceManifest.js.map +1 -1
- package/services/PulumiGetStackOutputService/mapStackOutput.js +1 -1
- package/services/PulumiGetStackOutputService/mapStackOutput.js.map +1 -1
- package/features/Watch/handler/handler.zip +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/api/ApiCloudfront.js","sources":["../../../../src/pulumi/apps/api/ApiCloudfront.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport type { PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\nimport { createAppModule } from \"@webiny/pulumi\";\n\nimport { ApiGateway } from \"./ApiGateway.js\";\nimport { ApiGraphqlStream } from \"./ApiGraphqlStream.js\";\n\nexport type ApiCloudfront = PulumiAppModule<typeof ApiCloudfront>;\n\nconst STREAM_ORIGIN_ID = \"graphql-stream-function-url\";\n\n// AWS's `Managed-CachingDisabled` cache policy. Managed policy IDs are global constants — the same\n// value in every account and region — so this is hardcoded rather than resolved via\n// `aws.cloudfront.getCachePolicyOutput({ name: \"Managed-CachingDisabled\" })` the way\n// `createCloudFrontDefaultCacheBehaviorPolicies` does. The lookup would need\n// `cloudfront:ListCachePolicies` on the deploy role, and that is not worth adding to every\n// project's default deployment path just to avoid a constant AWS itself documents.\nconst MANAGED_CACHING_DISABLED_POLICY_ID = \"4135ea2d-6df8-44a3-9df3-4b5a84be39ad\";\n\nexport const ApiCloudfront = createAppModule({\n name: \"ApiCloudfront\",\n config(app: PulumiApp) {\n const gateway = app.getModule(ApiGateway);\n const graphqlStream = app.getModule(ApiGraphqlStream);\n\n const cookies = {\n forward: \"whitelist\",\n whitelistedNames: [\"wby-id-token\"]\n };\n\n const forwardHeaders = [\n \"Origin\",\n \"Authorization\",\n \"Accept\",\n \"Accept-Language\",\n \"X-Tenant\",\n \"X-Webiny-Sdk\",\n // Narrows the debugger's capture. Without it here the edge drops the header silently.\n \"X-Webiny-Debug\"\n ];\n\n // Lets CloudFront sign requests to the Lambda Function URL with SigV4, so the URL itself can\n // stay on AWS_IAM authorization instead of being reachable from the internet.\n const streamOac = app.addResource(aws.cloudfront.OriginAccessControl, {\n name: \"api-stream-oac\",\n config: {\n description: \"Signs CloudFront requests to the streaming Lambda Function URL\",\n originAccessControlOriginType: \"lambda\",\n signingBehavior: \"always\",\n signingProtocol: \"sigv4\"\n }\n });\n\n // The streaming behavior uses a cache policy + origin request policy instead of the legacy\n // `forwardedValues` the other behaviors use, because legacy forwarded values are deprecated\n // and this policy also has to forward the two CORS preflight headers (see below).\n //\n // It is NOT what fixed the `AccessDeniedException` that made Lambda reject every signed\n // CloudFront request — that was a missing `lambda:InvokeFunction` permission (see the two\n // permissions at the bottom of this file). Recorded because the wrong cause was assumed first.\n //\n // Do NOT replace this with a managed origin request policy. `Managed-AllViewer` forwards\n // `Host`, which breaks OAC signing against a Function URL origin.\n // `Managed-AllViewerExceptHostHeader` (used for the blue/green router in this same package)\n // fixes `Host` but still forwards `Authorization`, which OAC signing owns here — see below.\n const streamOriginRequestPolicy = app.addResource(aws.cloudfront.OriginRequestPolicy, {\n name: \"api-stream-origin-request-policy\",\n config: {\n comment: \"Headers/cookies forwarded to the streaming Lambda Function URL origin\",\n headersConfig: {\n headerBehavior: \"whitelist\",\n headers: {\n items: [\n \"Origin\",\n \"Accept\",\n \"Accept-Language\",\n // Required for CORS preflight: without these the origin can't build a\n // correct 204, so the browser blocks the real request.\n \"Access-Control-Request-Method\",\n \"Access-Control-Request-Headers\",\n \"X-Tenant\",\n \"X-Webiny-Sdk\",\n // `Authorization` is deliberately ABSENT — OAC signing owns that header.\n // Clients send their token in `X-Webiny-Authorization` instead.\n \"X-Webiny-Authorization\"\n ]\n }\n },\n cookiesConfig: {\n cookieBehavior: \"whitelist\",\n cookies: { items: [\"wby-id-token\"] }\n },\n queryStringsConfig: { queryStringBehavior: \"all\" }\n }\n });\n\n const distribution = app.addResource(aws.cloudfront.Distribution, {\n name: \"api-cloudfront\",\n config: {\n httpVersion: \"http2and3\",\n waitForDeployment: false,\n isIpv6Enabled: true,\n enabled: true,\n defaultCacheBehavior: {\n compress: true,\n allowedMethods: [\"GET\", \"HEAD\", \"OPTIONS\", \"PUT\", \"POST\", \"PATCH\", \"DELETE\"],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies,\n headers: forwardHeaders,\n queryString: true\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 0,\n maxTtl: 86400,\n targetOriginId: gateway.api.output.name,\n viewerProtocolPolicy: \"allow-all\"\n },\n orderedCacheBehaviors: [\n {\n // Streaming routes (SSE). Must come before the other behaviors so `/stream/*`\n // never falls through to the API Gateway origin, which cannot stream.\n //\n // `compress: false` is load-bearing: CloudFront compression buffers small\n // chunks, which defeats incremental delivery even though the origin streams.\n compress: false,\n allowedMethods: [\n \"GET\",\n \"HEAD\",\n \"OPTIONS\",\n \"PUT\",\n \"POST\",\n \"PATCH\",\n \"DELETE\"\n ],\n cachedMethods: [\"GET\", \"HEAD\"],\n // Nothing on a streaming route is cacheable. TTLs must NOT be set\n // alongside a cache policy.\n cachePolicyId: MANAGED_CACHING_DISABLED_POLICY_ID,\n originRequestPolicyId: streamOriginRequestPolicy.output.id,\n pathPattern: \"/stream/*\",\n // Stricter than the other behaviors' `allow-all` on purpose: a streaming route\n // carries an auth token in a header, so plain HTTP is never acceptable here.\n viewerProtocolPolicy: \"https-only\",\n targetOriginId: STREAM_ORIGIN_ID\n },\n {\n compress: true,\n allowedMethods: [\n \"GET\",\n \"HEAD\",\n \"OPTIONS\",\n \"PUT\",\n \"POST\",\n \"PATCH\",\n \"DELETE\"\n ],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies: {\n forward: \"none\"\n },\n headers: forwardHeaders,\n queryString: true\n },\n pathPattern: \"/cms*\",\n viewerProtocolPolicy: \"allow-all\",\n targetOriginId: gateway.api.output.name\n },\n {\n compress: true,\n allowedMethods: [\n \"GET\",\n \"HEAD\",\n \"OPTIONS\",\n \"PUT\",\n \"POST\",\n \"PATCH\",\n \"DELETE\"\n ],\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies: {\n forward: \"none\"\n },\n headers: forwardHeaders,\n queryString: true\n },\n pathPattern: \"/wb/*\",\n viewerProtocolPolicy: \"allow-all\",\n targetOriginId: gateway.api.output.name\n },\n {\n allowedMethods: [\"HEAD\", \"GET\", \"OPTIONS\"],\n cachedMethods: [\"HEAD\", \"GET\", \"OPTIONS\"],\n forwardedValues: {\n cookies: {\n forward: \"none\"\n },\n headers: forwardHeaders,\n queryString: true\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 0,\n maxTtl: 2592000,\n pathPattern: \"/files/*\",\n viewerProtocolPolicy: \"allow-all\",\n targetOriginId: gateway.api.output.name\n },\n {\n allowedMethods: [\"HEAD\", \"GET\", \"OPTIONS\"],\n cachedMethods: [\"HEAD\", \"GET\", \"OPTIONS\"],\n forwardedValues: {\n cookies: cookies,\n headers: forwardHeaders,\n queryString: true\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 0,\n maxTtl: 2592000,\n pathPattern: \"/private/*\",\n viewerProtocolPolicy: \"allow-all\",\n targetOriginId: gateway.api.output.name\n }\n ],\n origins: [\n {\n domainName: gateway.stage.output.invokeUrl.apply(\n (url: string) => new URL(url).hostname\n ),\n originPath: gateway.stage.output.invokeUrl.apply(\n (url: string) => new URL(url).pathname\n ),\n originId: gateway.api.output.name,\n customOriginConfig: {\n httpPort: 80,\n httpsPort: 443,\n originProtocolPolicy: \"https-only\",\n originSslProtocols: [\"TLSv1.2\"]\n }\n },\n {\n // Lambda Function URL origin for streaming routes. A Function URL is a plain\n // HTTPS endpoint, hence customOriginConfig; the OAC is what makes CloudFront\n // sign the request so the URL can require AWS_IAM.\n domainName: graphqlStream.functionUrlDomain,\n originId: STREAM_ORIGIN_ID,\n originAccessControlId: streamOac.output.id,\n customOriginConfig: {\n httpPort: 80,\n httpsPort: 443,\n originProtocolPolicy: \"https-only\",\n originSslProtocols: [\"TLSv1.2\"],\n // NOT a cap on how long a response may stream. It is an IDLE timeout,\n // applied twice: to time-to-first-byte, and to the gap between any two\n // subsequent packets. A stream that keeps emitting can run as long as the\n // Lambda lives (300s here); only silence longer than this kills it.\n //\n // Raised from the 30s default because that is shorter than a slow model's\n // time to first token: CloudFront would abandon the stream while the Lambda\n // kept working. 60s is the ceiling without an AWS quota increase — a route\n // whose quiet gaps could exceed it must emit SSE heartbeat comments\n // (`: ping\\n\\n`), which clients ignore by spec, resetting the timer.\n originReadTimeout: 60\n }\n }\n ],\n restrictions: {\n geoRestriction: {\n restrictionType: \"none\"\n }\n },\n viewerCertificate: {\n cloudfrontDefaultCertificate: true\n }\n },\n opts: {\n // We are ignoring changes to the \"staging\" property. This is because of the following.\n // With the 5.41.0 release of Webiny, we also upgraded Pulumi to v6. This introduced a change\n // with how Cloudfront distributions are deployed, where Pulumi now also controls the new\n // `staging` property.\n // If not set, Pulumi will default it to `false`. Which is fine, but, the problem is\n // that, because this property did not exist before, it will always be considered as a change\n // upon deployment.\n // We might think this is fine, but, the problem is that a change in this property causes\n // a full replacement of the Cloudfront distribution, which is not acceptable. Especially\n // if a custom domain has already been associated with the distribution. This then would\n // require the user to disassociate the domain, wait for the distribution to be replaced,\n // and then re-associate the domain. This is not a good experience.\n ignoreChanges: [\"staging\"]\n }\n });\n\n // Allows THIS distribution — and nothing else — to invoke the streaming Function URL. Created\n // after the distribution because it needs its ARN; the Function URL is useless until it exists.\n //\n // BOTH statements are required. The OAC-for-Lambda docs list `lambda:InvokeFunctionUrl` AND\n // `lambda:InvokeFunction`; with only the former, Lambda's authorizer rejects every signed\n // request from CloudFront with `AccessDeniedException` and the function is never invoked.\n app.addResource(aws.lambda.Permission, {\n name: \"graphql-stream-url-cloudfront-invoke\",\n config: {\n action: \"lambda:InvokeFunctionUrl\",\n function: graphqlStream.functions.graphqlStream.output.name,\n principal: \"cloudfront.amazonaws.com\",\n sourceArn: distribution.output.arn,\n functionUrlAuthType: \"AWS_IAM\",\n statementId: \"allow-cloudfront-invoke-function-url\"\n }\n });\n\n app.addResource(aws.lambda.Permission, {\n name: \"graphql-stream-cloudfront-invoke-function\",\n config: {\n action: \"lambda:InvokeFunction\",\n function: graphqlStream.functions.graphqlStream.output.name,\n principal: \"cloudfront.amazonaws.com\",\n sourceArn: distribution.output.arn,\n statementId: \"allow-cloudfront-invoke-function\"\n }\n });\n\n return distribution;\n }\n});\n"],"names":["STREAM_ORIGIN_ID","MANAGED_CACHING_DISABLED_POLICY_ID","ApiCloudfront","createAppModule","app","gateway","ApiGateway","graphqlStream","ApiGraphqlStream","cookies","forwardHeaders","streamOac","aws","streamOriginRequestPolicy","distribution","url","URL"],"mappings":";;;;AASA,MAAMA,mBAAmB;AAQzB,MAAMC,qCAAqC;AAEpC,MAAMC,gBAAgBC,gBAAgB;IACzC,MAAM;IACN,QAAOC,GAAc;QACjB,MAAMC,UAAUD,IAAI,SAAS,CAACE;QAC9B,MAAMC,gBAAgBH,IAAI,SAAS,CAACI;QAEpC,MAAMC,UAAU;YACZ,SAAS;YACT,kBAAkB;gBAAC;aAAe;QACtC;QAEA,MAAMC,iBAAiB;YACnB;YACA;YACA;YACA;YACA;YACA;YAEA;SACH;QAID,MAAMC,YAAYP,IAAI,WAAW,CAACQ,uCAAAA,UAAAA,CAAAA,mBAAkC,EAAE;YAClE,MAAM;YACN,QAAQ;gBACJ,aAAa;gBACb,+BAA+B;gBAC/B,iBAAiB;gBACjB,iBAAiB;YACrB;QACJ;QAcA,MAAMC,4BAA4BT,IAAI,WAAW,CAACQ,uCAAAA,UAAAA,CAAAA,mBAAkC,EAAE;YAClF,MAAM;YACN,QAAQ;gBACJ,SAAS;gBACT,eAAe;oBACX,gBAAgB;oBAChB,SAAS;wBACL,OAAO;4BACH;4BACA;4BACA;4BAGA;4BACA;4BACA;4BACA;4BAGA;yBACH;oBACL;gBACJ;gBACA,eAAe;oBACX,gBAAgB;oBAChB,SAAS;wBAAE,OAAO;4BAAC;yBAAe;oBAAC;gBACvC;gBACA,oBAAoB;oBAAE,qBAAqB;gBAAM;YACrD;QACJ;QAEA,MAAME,eAAeV,IAAI,WAAW,CAACQ,uCAAAA,UAAAA,CAAAA,YAA2B,EAAE;YAC9D,MAAM;YACN,QAAQ;gBACJ,aAA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A8B;gBAClC;YACJ;YACA,MAAM;gBAaF,eAAe;oBAAC;iBAAU;YAC9B;QACJ;QAQAP,IAAI,WAAW,CAACQ,uCAAAA,MAAAA,CAAAA,UAAqB,EAAE;YACnC,MAAM;YACN,QAAQ;gBACJ,QAAQ;gBACR,UAAUL,cAAc,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI;gBAC3D,WAAW;gBACX,WAAWO,aAAa,MAAM,CAAC,GAAG;gBAClC,qBAAqB;gBACrB,aAAa;YACjB;QACJ;QAEAV,IAAI,WAAW,CAACQ,uCAAAA,MAAAA,CAAAA,UAAqB,EAAE;YACnC,MAAM;YACN,QAAQ;gBACJ,QAAQ;gBACR,UAAUL,cAAc,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI;gBAC3D,WAAW;gBACX,WAAWO,aAAa,MAAM,CAAC,GAAG;gBAClC,aAAa;YACjB;QACJ;QAEA,OAAOA;IACX;AACJ"}
|
|
1
|
+
{"version":3,"file":"pulumi/apps/api/ApiCloudfront.js","sources":["../../../../src/pulumi/apps/api/ApiCloudfront.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport type * as pulumi from \"@pulumi/pulumi\";\nimport type { PulumiApp } from \"@webiny/pulumi\";\nimport type { PulumiAppModule } from \"@webiny/pulumi\";\nimport { createAppModule } from \"@webiny/pulumi\";\n\nimport { ApiFileManager } from \"./ApiFileManager.js\";\nimport { ApiGateway } from \"./ApiGateway.js\";\nimport { ApiGraphqlStream } from \"./ApiGraphqlStream.js\";\nimport { ApiGraphqlWeb } from \"./ApiGraphqlWeb.js\";\nimport type { DistributionOrigin, OrderedCacheBehavior } from \"./cloudfront/constants.js\";\nimport {\n ALL_METHODS,\n API_VIEWER_HEADERS,\n FILES_ORIGIN_ID,\n FORWARD_HEADERS,\n ID_TOKEN_COOKIES\n} from \"./cloudfront/constants.js\";\nimport { createStreamRouting } from \"./cloudfront/createStreamRouting.js\";\nimport { createWebRouting } from \"./cloudfront/createWebRouting.js\";\nimport { createFilesRouting } from \"./cloudfront/createFilesRouting.js\";\nimport { createGatewayRouting } from \"./cloudfront/createGatewayRouting.js\";\nimport { allowFunctionUrlInvoke } from \"./cloudfront/allowFunctionUrlInvoke.js\";\nimport { allowWebFunctionInvoke } from \"./cloudfront/allowWebFunctionInvoke.js\";\nimport { addWebRouteBehavior } from \"./cloudfront/addWebRouteBehavior.js\";\n\nexport type ApiCloudfront = PulumiAppModule<typeof ApiCloudfront>;\n\n/**\n * The API's CloudFront distribution. Each origin's routing is built in `./cloudfront/`: the streaming\n * function always, then either the web function and `fm-download`, or API Gateway for projects that\n * turn the web function off.\n */\nexport const ApiCloudfront = createAppModule({\n name: \"ApiCloudfront\",\n config(app: PulumiApp) {\n const graphqlStream = app.getModule(ApiGraphqlStream);\n const fileManager = app.getModule(ApiFileManager);\n // Present unless the project sets `<Infra.Api.WebFunction enabled={false} />`.\n const graphqlWeb = app.getModule(ApiGraphqlWeb, { optional: true });\n // Present only without the web function.\n const gateway = app.getModule(ApiGateway, { optional: true });\n\n const stream = createStreamRouting(app, graphqlStream);\n\n const origins: DistributionOrigin[] = [stream.origin];\n // The routes that are not GraphQL: file delivery (`/files/*`, `/private/*` and the default\n // behavior, which serves files by alias) and, without the web function, everything else.\n let filesOriginId: pulumi.Input<string>;\n let filesForwardHeaders = FORWARD_HEADERS;\n const apiBehaviors: OrderedCacheBehavior[] = [];\n let routeCachePolicyId: pulumi.Input<string> | undefined;\n\n if (graphqlWeb) {\n const web = createWebRouting(app, graphqlWeb);\n routeCachePolicyId = web.routeCachePolicyId;\n origins.push(web.origin);\n apiBehaviors.push(...web.behaviors);\n\n const files = createFilesRouting(app, fileManager);\n origins.push(files.origin);\n filesOriginId = FILES_ORIGIN_ID;\n // An OAC signs every request to a Function URL, so `Authorization` belongs to the\n // signature. File requests authenticate with the `wby-id-token` cookie or with\n // `X-Webiny-Authorization`, which `fm-download` reads first.\n filesForwardHeaders = [...API_VIEWER_HEADERS, \"X-Webiny-Authorization\"];\n } else if (gateway) {\n const gatewayRouting = createGatewayRouting(gateway);\n // First, where it was before the web function existed, so projects that turn the web\n // function off see no change to the distribution.\n origins.unshift(gatewayRouting.origin);\n filesOriginId = gatewayRouting.originId;\n apiBehaviors.push(...gatewayRouting.behaviors);\n } else {\n throw new Error(\"The API has neither a web function nor an API Gateway to route to.\");\n }\n\n const distribution = app.addResource(aws.cloudfront.Distribution, {\n name: \"api-cloudfront\",\n config: {\n httpVersion: \"http2and3\",\n waitForDeployment: false,\n isIpv6Enabled: true,\n enabled: true,\n defaultCacheBehavior: {\n compress: true,\n allowedMethods: ALL_METHODS,\n cachedMethods: [\"GET\", \"HEAD\", \"OPTIONS\"],\n forwardedValues: {\n cookies: ID_TOKEN_COOKIES,\n headers: filesForwardHeaders,\n queryString: true\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 0,\n maxTtl: 86400,\n targetOriginId: filesOriginId,\n viewerProtocolPolicy: \"allow-all\"\n },\n orderedCacheBehaviors: [\n stream.behavior,\n ...apiBehaviors,\n {\n allowedMethods: [\"HEAD\", \"GET\", \"OPTIONS\"],\n cachedMethods: [\"HEAD\", \"GET\", \"OPTIONS\"],\n forwardedValues: {\n cookies: {\n forward: \"none\"\n },\n headers: filesForwardHeaders,\n queryString: true\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 0,\n maxTtl: 2592000,\n pathPattern: \"/files/*\",\n viewerProtocolPolicy: \"allow-all\",\n targetOriginId: filesOriginId\n },\n {\n allowedMethods: [\"HEAD\", \"GET\", \"OPTIONS\"],\n cachedMethods: [\"HEAD\", \"GET\", \"OPTIONS\"],\n forwardedValues: {\n cookies: ID_TOKEN_COOKIES,\n headers: filesForwardHeaders,\n queryString: true\n },\n // MinTTL <= DefaultTTL <= MaxTTL\n minTtl: 0,\n defaultTtl: 0,\n maxTtl: 2592000,\n pathPattern: \"/private/*\",\n viewerProtocolPolicy: \"allow-all\",\n targetOriginId: filesOriginId\n }\n ],\n origins,\n restrictions: {\n geoRestriction: {\n restrictionType: \"none\"\n }\n },\n viewerCertificate: {\n cloudfrontDefaultCertificate: true\n }\n },\n opts: {\n // We are ignoring changes to the \"staging\" property. This is because of the following.\n // With the 5.41.0 release of Webiny, we also upgraded Pulumi to v6. This introduced a change\n // with how Cloudfront distributions are deployed, where Pulumi now also controls the new\n // `staging` property.\n // If not set, Pulumi will default it to `false`. Which is fine, but, the problem is\n // that, because this property did not exist before, it will always be considered as a change\n // upon deployment.\n // We might think this is fine, but, the problem is that a change in this property causes\n // a full replacement of the Cloudfront distribution, which is not acceptable. Especially\n // if a custom domain has already been associated with the distribution. This then would\n // require the user to disassociate the domain, wait for the distribution to be replaced,\n // and then re-associate the domain. This is not a good experience.\n ignoreChanges: [\"staging\"]\n }\n });\n\n allowFunctionUrlInvoke(app, {\n name: \"graphql-stream\",\n functionName: graphqlStream.functions.graphqlStream.output.name,\n distributionArn: distribution.output.arn\n });\n\n if (graphqlWeb) {\n allowFunctionUrlInvoke(app, {\n name: \"fm-download\",\n functionName: fileManager.functions.download.output.name,\n distributionArn: distribution.output.arn\n });\n allowWebFunctionInvoke(app, graphqlWeb, distribution.output.arn);\n }\n\n if (graphqlWeb && routeCachePolicyId) {\n const policyId = routeCachePolicyId;\n // `<Api.Route>` routes. Their `ApiPulumi` handler runs before any resource is created,\n // so the distribution's config can still change when a route arrives.\n graphqlWeb.onRoute(routePath => {\n addWebRouteBehavior(distribution, routePath, policyId);\n });\n }\n\n return distribution;\n }\n});\n"],"names":["ApiCloudfront","createAppModule","app","graphqlStream","ApiGraphqlStream","fileManager","ApiFileManager","graphqlWeb","ApiGraphqlWeb","gateway","ApiGateway","stream","createStreamRouting","origins","filesOriginId","filesForwardHeaders","FORWARD_HEADERS","apiBehaviors","routeCachePolicyId","web","createWebRouting","files","createFilesRouting","FILES_ORIGIN_ID","API_VIEWER_HEADERS","gatewayRouting","createGatewayRouting","Error","distribution","aws","ALL_METHOD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AuB/B,KAAKK,YAAYqB,aAAa,MAAM,CAAC,GAAG;QACnE;QAEA,IAAIrB,cAAcW,oBAAoB;YAClC,MAAMgB,WAAWhB;YAGjBX,WAAW,OAAO,CAAC4B,CAAAA;gBACfC,oBAAoBR,cAAcO,WAAWD;YACjD;QACJ;QAEA,OAAON;IACX;AACJ"}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import type { PulumiAppModule } from "@webiny/pulumi";
|
|
2
|
+
import type { PulumiAppResource } from "@webiny/pulumi";
|
|
2
3
|
export type ApiFileManager = PulumiAppModule<typeof ApiFileManager>;
|
|
3
4
|
interface ApiFileManagerConfig {
|
|
4
5
|
env: Record<string, any>;
|
|
6
|
+
/**
|
|
7
|
+
* With the web function there is no HTTP API Gateway, so CloudFront reaches `fm-download` through
|
|
8
|
+
* a Function URL instead, signed by an OAC.
|
|
9
|
+
*/
|
|
10
|
+
functionUrl: boolean;
|
|
5
11
|
}
|
|
6
12
|
export declare const ApiFileManager: import("@webiny/pulumi").PulumiAppModuleDefinition<{
|
|
7
13
|
functions: {
|
|
8
|
-
download:
|
|
14
|
+
download: PulumiAppResource<typeof import("@pulumi/aws/lambda/function").Function>;
|
|
9
15
|
};
|
|
16
|
+
functionUrl: PulumiAppResource<typeof import("@pulumi/aws/lambda/functionUrl").FunctionUrl> | null;
|
|
10
17
|
}, ApiFileManagerConfig>;
|
|
11
18
|
export {};
|
|
@@ -28,10 +28,20 @@ const ApiFileManager = createAppModule({
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
+
let functionUrl = null;
|
|
32
|
+
if (config.functionUrl) functionUrl = app.addResource(__rspack_external__pulumi_aws_9e2bee2d.lambda.FunctionUrl, {
|
|
33
|
+
name: "fm-download-url",
|
|
34
|
+
config: {
|
|
35
|
+
functionName: download.output.name,
|
|
36
|
+
authorizationType: "AWS_IAM",
|
|
37
|
+
invokeMode: "BUFFERED"
|
|
38
|
+
}
|
|
39
|
+
});
|
|
31
40
|
return {
|
|
32
41
|
functions: {
|
|
33
42
|
download
|
|
34
|
-
}
|
|
43
|
+
},
|
|
44
|
+
functionUrl
|
|
35
45
|
};
|
|
36
46
|
}
|
|
37
47
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/api/ApiFileManager.js","sources":["../../../../src/pulumi/apps/api/ApiFileManager.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport { getLayerArn } from \"@webiny/aws-layers\";\nimport type { PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\nimport { createAppModule } from \"@webiny/pulumi\";\n\nimport { ApiGraphql } from \"~/pulumi/apps/index.js\";\n\nexport type ApiFileManager = PulumiAppModule<typeof ApiFileManager>;\n\ninterface ApiFileManagerConfig {\n env: Record<string, any>;\n}\n\nexport const ApiFileManager = createAppModule({\n name: \"ApiFileManager\",\n config(app: PulumiApp, config: ApiFileManagerConfig) {\n const graphql = app.getModule(ApiGraphql);\n\n const baseConfig = graphql.functions.graphql.config.clone();\n\n const download = app.addResource(aws.lambda.Function, {\n name: \"fm-download\",\n config: {\n ...baseConfig,\n memorySize: 1600,\n description: \"Serves previously uploaded files.\",\n layers: [getLayerArn(\"sharp\")],\n environment: {\n variables: graphql.functions.graphql.output.environment.apply(env => {\n return {\n WEBINY_FUNCTION_TYPE: \"asset-delivery\",\n ...env?.variables,\n ...config.env\n };\n })\n },\n loggingConfig: {\n logFormat: \"JSON\"\n }\n }\n });\n\n return {\n functions: {\n download\n }\n };\n }\n});\n"],"names":["ApiFileManager","createAppModule","app","config","graphql","ApiGraphql","baseConfig","download","aws","getLayerArn","env"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"pulumi/apps/api/ApiFileManager.js","sources":["../../../../src/pulumi/apps/api/ApiFileManager.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport { getLayerArn } from \"@webiny/aws-layers\";\nimport type { PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\nimport type { PulumiAppResource } from \"@webiny/pulumi\";\nimport { createAppModule } from \"@webiny/pulumi\";\n\nimport { ApiGraphql } from \"~/pulumi/apps/index.js\";\n\nexport type ApiFileManager = PulumiAppModule<typeof ApiFileManager>;\n\ninterface ApiFileManagerConfig {\n env: Record<string, any>;\n /**\n * With the web function there is no HTTP API Gateway, so CloudFront reaches `fm-download` through\n * a Function URL instead, signed by an OAC.\n */\n functionUrl: boolean;\n}\n\nexport const ApiFileManager = createAppModule({\n name: \"ApiFileManager\",\n config(app: PulumiApp, config: ApiFileManagerConfig) {\n const graphql = app.getModule(ApiGraphql);\n\n const baseConfig = graphql.functions.graphql.config.clone();\n\n const download = app.addResource(aws.lambda.Function, {\n name: \"fm-download\",\n config: {\n ...baseConfig,\n memorySize: 1600,\n description: \"Serves previously uploaded files.\",\n layers: [getLayerArn(\"sharp\")],\n environment: {\n variables: graphql.functions.graphql.output.environment.apply(env => {\n return {\n WEBINY_FUNCTION_TYPE: \"asset-delivery\",\n ...env?.variables,\n ...config.env\n };\n })\n },\n loggingConfig: {\n logFormat: \"JSON\"\n }\n }\n });\n\n let functionUrl: PulumiAppResource<typeof aws.lambda.FunctionUrl> | null = null;\n if (config.functionUrl) {\n functionUrl = app.addResource(aws.lambda.FunctionUrl, {\n name: \"fm-download-url\",\n config: {\n functionName: download.output.name,\n // Only CloudFront may call it; see the OAC and permissions in ApiCloudfront.\n authorizationType: \"AWS_IAM\",\n invokeMode: \"BUFFERED\"\n }\n });\n }\n\n return {\n functions: {\n download\n },\n functionUrl\n };\n }\n});\n"],"names":["ApiFileManager","createAppModule","app","config","graphql","ApiGraphql","baseConfig","download","aws","getLayerArn","env","functionUrl"],"mappings":";;;;AAmBO,MAAMA,iBAAiBC,gBAAgB;IAC1C,MAAM;IACN,QAAOC,GAAc,EAAEC,MAA4B;QAC/C,MAAMC,UAAUF,IAAI,SAAS,CAACG;QAE9B,MAAMC,aAAaF,QAAQ,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK;QAEzD,MAAMG,WAAWL,IAAI,WAAW,CAACM,uCAAAA,MAAAA,CAAAA,QAAmB,EAAE;YAClD,MAAM;YACN,QAAQ;gBACJ,GAAGF,UAAU;gBACb,YAAY;gBACZ,aAAa;gBACb,QAAQ;oBAACG,YAAY;iBAAS;gBAC9B,aAAa;oBACT,WAAWL,QAAQ,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAACM,CAAAA,MACnD;4BACH,sBAAsB;4BACtB,GAAGA,KAAK,SAAS;4BACjB,GAAGP,OAAO,GAAG;wBACjB;gBAER;gBACA,eAAe;oBACX,WAAW;gBACf;YACJ;QACJ;QAEA,IAAIQ,cAAuE;QAC3E,IAAIR,OAAO,WAAW,EAClBQ,cAAcT,IAAI,WAAW,CAACM,uCAAAA,MAAAA,CAAAA,WAAsB,EAAE;YAClD,MAAM;YACN,QAAQ;gBACJ,cAAcD,SAAS,MAAM,CAAC,IAAI;gBAElC,mBAAmB;gBACnB,YAAY;YAChB;QACJ;QAGJ,OAAO;YACH,WAAW;gBACPA;YACJ;YACAI;QACJ;IACJ;AACJ"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import kebabCase from "lodash/kebabCase.js";
|
|
3
2
|
import { createAppModule } from "@webiny/pulumi";
|
|
4
3
|
import { createLambdaRole, getCommonLambdaEnvVariables } from "../lambdaUtils.js";
|
|
5
4
|
import { CoreOutput, VpcConfig } from "../index.js";
|
|
6
5
|
import { getAwsAccountId, getAwsRegion } from "../awsUtils.js";
|
|
7
6
|
import { LAMBDA_RUNTIME } from "../../constants.js";
|
|
7
|
+
import { ApiGraphqlWeb } from "./ApiGraphqlWeb.js";
|
|
8
|
+
import { isRouteNameAllowed } from "./isRouteNameAllowed.js";
|
|
8
9
|
import * as __rspack_external__pulumi_pulumi_f3e773ed from "@pulumi/pulumi";
|
|
9
10
|
import * as __rspack_external__pulumi_aws_9e2bee2d from "@pulumi/aws";
|
|
10
11
|
const EMPTY_TRASH_BIN_EVENT_RULE_NAME = "empty-trash-bin-event-rule";
|
|
@@ -77,10 +78,13 @@ const ApiGraphql = createAppModule({
|
|
|
77
78
|
graphql
|
|
78
79
|
},
|
|
79
80
|
addRoute: (routeParams)=>{
|
|
81
|
+
const graphqlWeb = app.getModule(ApiGraphqlWeb, {
|
|
82
|
+
optional: true
|
|
83
|
+
});
|
|
84
|
+
if (graphqlWeb) return void graphqlWeb.addRoute(routeParams.path);
|
|
85
|
+
if (!isRouteNameAllowed(routeParams.name)) return void console.log(`Route name is not allowed: "${routeParams.name}".`);
|
|
80
86
|
const apiGateway = app.resources.apiGateway;
|
|
81
87
|
if (!apiGateway) return void console.log("Could not add route because there is no apiGateway in the resources.");
|
|
82
|
-
const kebabName = kebabCase(routeParams.name);
|
|
83
|
-
if (kebabName !== routeParams.name) return void console.log(`Route name is not allowed: "${routeParams.name}".`);
|
|
84
88
|
return apiGateway.addRoute(routeParams.name, {
|
|
85
89
|
path: routeParams.path,
|
|
86
90
|
method: routeParams.method,
|
|
@@ -104,72 +108,7 @@ function createGraphqlLambdaPolicy(app) {
|
|
|
104
108
|
const policy = {
|
|
105
109
|
Version: "2012-10-17",
|
|
106
110
|
Statement: [
|
|
107
|
-
|
|
108
|
-
Sid: "PermissionForDynamodb",
|
|
109
|
-
Effect: "Allow",
|
|
110
|
-
Action: [
|
|
111
|
-
"dynamodb:BatchGetItem",
|
|
112
|
-
"dynamodb:BatchWriteItem",
|
|
113
|
-
"dynamodb:ConditionCheckItem",
|
|
114
|
-
"dynamodb:CreateBackup",
|
|
115
|
-
"dynamodb:CreateTable",
|
|
116
|
-
"dynamodb:CreateTableReplica",
|
|
117
|
-
"dynamodb:DeleteBackup",
|
|
118
|
-
"dynamodb:DeleteItem",
|
|
119
|
-
"dynamodb:DeleteTable",
|
|
120
|
-
"dynamodb:DeleteTableReplica",
|
|
121
|
-
"dynamodb:DescribeBackup",
|
|
122
|
-
"dynamodb:DescribeContinuousBackups",
|
|
123
|
-
"dynamodb:DescribeContributorInsights",
|
|
124
|
-
"dynamodb:DescribeExport",
|
|
125
|
-
"dynamodb:DescribeKinesisStreamingDestination",
|
|
126
|
-
"dynamodb:DescribeLimits",
|
|
127
|
-
"dynamodb:DescribeReservedCapacity",
|
|
128
|
-
"dynamodb:DescribeReservedCapacityOfferings",
|
|
129
|
-
"dynamodb:DescribeStream",
|
|
130
|
-
"dynamodb:DescribeTable",
|
|
131
|
-
"dynamodb:DescribeTableReplicaAutoScaling",
|
|
132
|
-
"dynamodb:DescribeTimeToLive",
|
|
133
|
-
"dynamodb:DisableKinesisStreamingDestination",
|
|
134
|
-
"dynamodb:EnableKinesisStreamingDestination",
|
|
135
|
-
"dynamodb:ExportTableToPointInTime",
|
|
136
|
-
"dynamodb:GetItem",
|
|
137
|
-
"dynamodb:GetRecords",
|
|
138
|
-
"dynamodb:GetShardIterator",
|
|
139
|
-
"dynamodb:ListBackups",
|
|
140
|
-
"dynamodb:ListContributorInsights",
|
|
141
|
-
"dynamodb:ListExports",
|
|
142
|
-
"dynamodb:ListStreams",
|
|
143
|
-
"dynamodb:ListTables",
|
|
144
|
-
"dynamodb:ListTagsOfResource",
|
|
145
|
-
"dynamodb:PartiQLDelete",
|
|
146
|
-
"dynamodb:PartiQLInsert",
|
|
147
|
-
"dynamodb:PartiQLSelect",
|
|
148
|
-
"dynamodb:PartiQLUpdate",
|
|
149
|
-
"dynamodb:PurchaseReservedCapacityOfferings",
|
|
150
|
-
"dynamodb:PutItem",
|
|
151
|
-
"dynamodb:Query",
|
|
152
|
-
"dynamodb:RestoreTableFromBackup",
|
|
153
|
-
"dynamodb:RestoreTableToPointInTime",
|
|
154
|
-
"dynamodb:Scan",
|
|
155
|
-
"dynamodb:UpdateContinuousBackups",
|
|
156
|
-
"dynamodb:UpdateContributorInsights",
|
|
157
|
-
"dynamodb:UpdateItem",
|
|
158
|
-
"dynamodb:UpdateTable",
|
|
159
|
-
"dynamodb:UpdateTableReplicaAutoScaling",
|
|
160
|
-
"dynamodb:UpdateTimeToLive"
|
|
161
|
-
],
|
|
162
|
-
Resource: [
|
|
163
|
-
`${core.primaryDynamodbTableArn}`,
|
|
164
|
-
`${core.primaryDynamodbTableArn}/*`,
|
|
165
|
-
`${core.auditLogsDynamodbTableArn}`,
|
|
166
|
-
`${core.auditLogsDynamodbTableArn}/*`,
|
|
167
|
-
...core.opensearchDynamodbTableArn ? [
|
|
168
|
-
`${core.opensearchDynamodbTableArn}`,
|
|
169
|
-
`${core.opensearchDynamodbTableArn}/*`
|
|
170
|
-
] : []
|
|
171
|
-
]
|
|
172
|
-
},
|
|
111
|
+
...createDynamoDbStatements(core),
|
|
173
112
|
{
|
|
174
113
|
Sid: "PermissionForS3",
|
|
175
114
|
Effect: "Allow",
|
|
@@ -230,6 +169,76 @@ function createGraphqlLambdaPolicy(app) {
|
|
|
230
169
|
}
|
|
231
170
|
});
|
|
232
171
|
}
|
|
172
|
+
function createDynamoDbStatements(core) {
|
|
173
|
+
const tableArns = [
|
|
174
|
+
core.primaryDynamodbTableArn,
|
|
175
|
+
core.auditLogsDynamodbTableArn,
|
|
176
|
+
core.opensearchDynamodbTableArn
|
|
177
|
+
].filter((arn)=>Boolean(arn));
|
|
178
|
+
if (!tableArns.length) return [];
|
|
179
|
+
return [
|
|
180
|
+
{
|
|
181
|
+
Sid: "PermissionForDynamodb",
|
|
182
|
+
Effect: "Allow",
|
|
183
|
+
Action: [
|
|
184
|
+
"dynamodb:BatchGetItem",
|
|
185
|
+
"dynamodb:BatchWriteItem",
|
|
186
|
+
"dynamodb:ConditionCheckItem",
|
|
187
|
+
"dynamodb:CreateBackup",
|
|
188
|
+
"dynamodb:CreateTable",
|
|
189
|
+
"dynamodb:CreateTableReplica",
|
|
190
|
+
"dynamodb:DeleteBackup",
|
|
191
|
+
"dynamodb:DeleteItem",
|
|
192
|
+
"dynamodb:DeleteTable",
|
|
193
|
+
"dynamodb:DeleteTableReplica",
|
|
194
|
+
"dynamodb:DescribeBackup",
|
|
195
|
+
"dynamodb:DescribeContinuousBackups",
|
|
196
|
+
"dynamodb:DescribeContributorInsights",
|
|
197
|
+
"dynamodb:DescribeExport",
|
|
198
|
+
"dynamodb:DescribeKinesisStreamingDestination",
|
|
199
|
+
"dynamodb:DescribeLimits",
|
|
200
|
+
"dynamodb:DescribeReservedCapacity",
|
|
201
|
+
"dynamodb:DescribeReservedCapacityOfferings",
|
|
202
|
+
"dynamodb:DescribeStream",
|
|
203
|
+
"dynamodb:DescribeTable",
|
|
204
|
+
"dynamodb:DescribeTableReplicaAutoScaling",
|
|
205
|
+
"dynamodb:DescribeTimeToLive",
|
|
206
|
+
"dynamodb:DisableKinesisStreamingDestination",
|
|
207
|
+
"dynamodb:EnableKinesisStreamingDestination",
|
|
208
|
+
"dynamodb:ExportTableToPointInTime",
|
|
209
|
+
"dynamodb:GetItem",
|
|
210
|
+
"dynamodb:GetRecords",
|
|
211
|
+
"dynamodb:GetShardIterator",
|
|
212
|
+
"dynamodb:ListBackups",
|
|
213
|
+
"dynamodb:ListContributorInsights",
|
|
214
|
+
"dynamodb:ListExports",
|
|
215
|
+
"dynamodb:ListStreams",
|
|
216
|
+
"dynamodb:ListTables",
|
|
217
|
+
"dynamodb:ListTagsOfResource",
|
|
218
|
+
"dynamodb:PartiQLDelete",
|
|
219
|
+
"dynamodb:PartiQLInsert",
|
|
220
|
+
"dynamodb:PartiQLSelect",
|
|
221
|
+
"dynamodb:PartiQLUpdate",
|
|
222
|
+
"dynamodb:PurchaseReservedCapacityOfferings",
|
|
223
|
+
"dynamodb:PutItem",
|
|
224
|
+
"dynamodb:Query",
|
|
225
|
+
"dynamodb:RestoreTableFromBackup",
|
|
226
|
+
"dynamodb:RestoreTableToPointInTime",
|
|
227
|
+
"dynamodb:Scan",
|
|
228
|
+
"dynamodb:UpdateContinuousBackups",
|
|
229
|
+
"dynamodb:UpdateContributorInsights",
|
|
230
|
+
"dynamodb:UpdateItem",
|
|
231
|
+
"dynamodb:UpdateTable",
|
|
232
|
+
"dynamodb:UpdateTableReplicaAutoScaling",
|
|
233
|
+
"dynamodb:UpdateTimeToLive"
|
|
234
|
+
],
|
|
235
|
+
Resource: tableArns.flatMap((arn)=>[
|
|
236
|
+
arn,
|
|
237
|
+
`${arn}/*`
|
|
238
|
+
])
|
|
239
|
+
}
|
|
240
|
+
];
|
|
241
|
+
}
|
|
233
242
|
export { ApiGraphql };
|
|
234
243
|
|
|
235
244
|
//# sourceMappingURL=ApiGraphql.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/api/ApiGraphql.js","sources":["../../../../src/pulumi/apps/api/ApiGraphql.ts"],"sourcesContent":["import path from \"path\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as aws from \"@pulumi/aws\";\nimport toKebabCase from \"lodash/kebabCase.js\";\nimport type { PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\nimport { createAppModule } from \"@webiny/pulumi\";\nimport { createLambdaRole, getCommonLambdaEnvVariables } from \"../lambdaUtils.js\";\nimport { CoreOutput, VpcConfig } from \"~/pulumi/apps/index.js\";\nimport { getAwsAccountId, getAwsRegion } from \"../awsUtils.js\";\nimport { LAMBDA_RUNTIME } from \"~/pulumi/constants.js\";\n\ninterface GraphqlParams {\n env: Record<string, any>;\n}\n\nexport interface AddRouteParams {\n /**\n * Must be in kebab case (a-z and -)\n */\n name: string;\n path: `/${string}`;\n method: \"DELETE\" | \"GET\" | \"HEAD\" | \"PATCH\" | \"POST\" | \"PUT\" | \"OPTIONS\" | \"ANY\";\n}\n\nconst EMPTY_TRASH_BIN_EVENT_RULE_NAME = `empty-trash-bin-event-rule`;\nconst EMPTY_TRASH_BIN_EVENT_PERMISSION_NAME = `empty-trash-bin-event-target-permission`;\nconst EMPTY_TRASH_BIN_EVENT_RULE_TARGET = `empty-trash-bin-event-rule-target`;\n\nexport type ApiGraphql = PulumiAppModule<typeof ApiGraphql>;\n\nexport const ApiGraphql = createAppModule({\n name: \"ApiGraphql\",\n config(app: PulumiApp, params: GraphqlParams) {\n const policy = createGraphqlLambdaPolicy(app);\n const role = createLambdaRole(app, {\n name: \"api-lambda-role\",\n policy: policy.output\n });\n\n const graphql = app.addResource(aws.lambda.Function, {\n name: \"graphql\",\n config: {\n description: \"Webiny's GraphQL APIs\",\n runtime: LAMBDA_RUNTIME,\n handler: \"handler.handler\",\n role: role.output.arn,\n timeout: 30,\n memorySize: 1024,\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"graphql/build\")\n )\n }),\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n ...params.env,\n AWS_NODEJS_CONNECTION_REUSE_ENABLED: \"1\"\n }))\n },\n vpcConfig: app.getModule(VpcConfig).functionVpcConfig,\n loggingConfig: {\n logFormat: \"JSON\"\n }\n }\n });\n\n // Create event rule.\n const eventRule = app.addResource(aws.cloudwatch.EventRule, {\n name: EMPTY_TRASH_BIN_EVENT_RULE_NAME,\n config: {\n description: \"Enable us to empty the trash-bin ever day\",\n scheduleExpression: \"cron(0 3 * * ? *)\"\n }\n });\n\n // Add required permission to the target lambda.\n app.addResource(aws.lambda.Permission, {\n name: EMPTY_TRASH_BIN_EVENT_PERMISSION_NAME,\n config: {\n action: \"lambda:InvokeFunction\",\n function: graphql.output.arn,\n principal: \"events.amazonaws.com\",\n statementId: \"allow-rule-invoke-\" + EMPTY_TRASH_BIN_EVENT_RULE_NAME\n }\n });\n\n // Target the main graphql lambda.\n app.addResource(aws.cloudwatch.EventTarget, {\n name: EMPTY_TRASH_BIN_EVENT_RULE_TARGET,\n config: {\n rule: eventRule.output.name,\n arn: graphql.output.arn,\n input: JSON.stringify({\n source: \"webiny.events\",\n \"detail-type\": \"WebinyEmptyTrashBin\"\n })\n }\n });\n\n return {\n role,\n policy,\n functions: {\n graphql\n },\n addRoute: (routeParams: AddRouteParams) => {\n const apiGateway: any = app.resources.apiGateway;\n if (!apiGateway) {\n console.log(\n \"Could not add route because there is no apiGateway in the resources.\"\n );\n return;\n }\n const kebabName = toKebabCase(routeParams.name);\n if (kebabName !== routeParams.name) {\n console.log(`Route name is not allowed: \"${routeParams.name}\".`);\n return;\n }\n return apiGateway.addRoute(routeParams.name, {\n path: routeParams.path,\n method: routeParams.method,\n function: graphql.output.arn\n });\n }\n };\n }\n});\n\nfunction createGraphqlLambdaPolicy(app: PulumiApp) {\n const coreOutput = app.getModule(CoreOutput);\n const awsAccountId = getAwsAccountId(app);\n const awsRegion = getAwsRegion(app);\n\n return app.addResource(aws.iam.Policy, {\n name: \"ApiGraphqlLambdaPolicy\",\n config: {\n description: \"This policy enables access to Dynamodb, S3, Lambda and Cognito IDP\",\n // Core is pulumi.Output, so we need to run apply() to resolve policy based on it\n policy: pulumi.all([coreOutput]).apply(([core]) => {\n const policy: aws.iam.PolicyDocument = {\n Version: \"2012-10-17\",\n Statement: [\n {\n Sid: \"PermissionForDynamodb\",\n Effect: \"Allow\",\n Action: [\n \"dynamodb:BatchGetItem\",\n \"dynamodb:BatchWriteItem\",\n \"dynamodb:ConditionCheckItem\",\n \"dynamodb:CreateBackup\",\n \"dynamodb:CreateTable\",\n \"dynamodb:CreateTableReplica\",\n \"dynamodb:DeleteBackup\",\n \"dynamodb:DeleteItem\",\n \"dynamodb:DeleteTable\",\n \"dynamodb:DeleteTableReplica\",\n \"dynamodb:DescribeBackup\",\n \"dynamodb:DescribeContinuousBackups\",\n \"dynamodb:DescribeContributorInsights\",\n \"dynamodb:DescribeExport\",\n \"dynamodb:DescribeKinesisStreamingDestination\",\n \"dynamodb:DescribeLimits\",\n \"dynamodb:DescribeReservedCapacity\",\n \"dynamodb:DescribeReservedCapacityOfferings\",\n \"dynamodb:DescribeStream\",\n \"dynamodb:DescribeTable\",\n \"dynamodb:DescribeTableReplicaAutoScaling\",\n \"dynamodb:DescribeTimeToLive\",\n \"dynamodb:DisableKinesisStreamingDestination\",\n \"dynamodb:EnableKinesisStreamingDestination\",\n \"dynamodb:ExportTableToPointInTime\",\n \"dynamodb:GetItem\",\n \"dynamodb:GetRecords\",\n \"dynamodb:GetShardIterator\",\n \"dynamodb:ListBackups\",\n \"dynamodb:ListContributorInsights\",\n \"dynamodb:ListExports\",\n \"dynamodb:ListStreams\",\n \"dynamodb:ListTables\",\n \"dynamodb:ListTagsOfResource\",\n \"dynamodb:PartiQLDelete\",\n \"dynamodb:PartiQLInsert\",\n \"dynamodb:PartiQLSelect\",\n \"dynamodb:PartiQLUpdate\",\n \"dynamodb:PurchaseReservedCapacityOfferings\",\n \"dynamodb:PutItem\",\n \"dynamodb:Query\",\n \"dynamodb:RestoreTableFromBackup\",\n \"dynamodb:RestoreTableToPointInTime\",\n \"dynamodb:Scan\",\n \"dynamodb:UpdateContinuousBackups\",\n \"dynamodb:UpdateContributorInsights\",\n \"dynamodb:UpdateItem\",\n \"dynamodb:UpdateTable\",\n \"dynamodb:UpdateTableReplicaAutoScaling\",\n \"dynamodb:UpdateTimeToLive\"\n ],\n Resource: [\n `${core.primaryDynamodbTableArn}`,\n `${core.primaryDynamodbTableArn}/*`,\n `${core.auditLogsDynamodbTableArn}`,\n `${core.auditLogsDynamodbTableArn}/*`,\n // Attach permissions for elastic search dynamo as well (if ES is enabled).\n ...(core.opensearchDynamodbTableArn\n ? [\n `${core.opensearchDynamodbTableArn}`,\n `${core.opensearchDynamodbTableArn}/*`\n ]\n : [])\n ]\n },\n {\n Sid: \"PermissionForS3\",\n Effect: \"Allow\",\n Action: [\n \"s3:ListBucket\",\n \"s3:GetObjectAcl\",\n \"s3:DeleteObject\",\n \"s3:PutObjectAcl\",\n \"s3:PutObject\",\n \"s3:GetObject\"\n ],\n Resource: [\n pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}`,\n pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}/*`\n ]\n },\n {\n Sid: \"PermissionForLambda\",\n Effect: \"Allow\",\n Action: [\"lambda:InvokeFunction\"],\n Resource: pulumi.interpolate`arn:aws:lambda:${awsRegion}:${awsAccountId}:function:*`\n },\n {\n Sid: \"PermissionForCognitoIdp\",\n Effect: \"Allow\",\n Action: \"cognito-idp:*\",\n Resource: `${core.cognitoUserPoolArn}`\n },\n {\n Sid: \"PermissionForEventBus\",\n Effect: \"Allow\",\n Action: \"events:PutEvents\",\n Resource: core.eventBusArn\n },\n {\n Sid: \"PermissionForCloudfront\",\n Effect: \"Allow\",\n Action: \"cloudfront:CreateInvalidation\",\n Resource: pulumi.interpolate`arn:aws:cloudfront::${awsAccountId}:distribution/*`\n },\n // Attach permissions for elastic search domain as well (if ES is enabled).\n ...(core.opensearchDomainArn\n ? [\n {\n Sid: \"PermissionForOS\",\n Effect: \"Allow\" as const,\n Action: \"es:*\",\n Resource: [\n `${core.opensearchDomainArn}`,\n `${core.opensearchDomainArn}/*`\n ]\n }\n ]\n : [])\n ]\n };\n\n return policy;\n })\n }\n });\n}\n"],"names":["EMPTY_TRASH_BIN_EVENT_RULE_NAME","EMPTY_TRASH_BIN_EVENT_PERMISSION_NAME","EMPTY_TRASH_BIN_EVENT_RULE_TARGET","ApiGraphql","createAppModule","app","params","policy","createGraphqlLambdaPolicy","role","createLambdaRole","graphql","aws","LAMBDA_RUNTIME","pulumi","path","getCommonLambdaEnvVariables","value","VpcConfig","eventRule","JSON","routeParams","apiGateway","console","kebabName","toKebabCase","coreOutput","CoreOutput","awsAccountId","getAwsAccountId","awsRegion","getAwsRegion","core"],"mappings":";;;;;;;;;AAwBA,MAAMA,kCAAkC;AACxC,MAAMC,wCAAwC;AAC9C,MAAMC,oCAAoC;AAInC,MAAMC,aAAaC,gBAAgB;IACtC,MAAM;IACN,QAAOC,GAAc,EAAEC,MAAqB;QACxC,MAAMC,SAASC,0BAA0BH;QACzC,MAAMI,OAAOC,iBAAiBL,KAAK;YAC/B,MAAM;YACN,QAAQE,OAAO,MAAM;QACzB;QAEA,MAAMI,UAAUN,IAAI,WAAW,CAACO,uCAAAA,MAAAA,CAAAA,QAAmB,EAAE;YACjD,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B,CAAC,EAAE,CAAC;mCAEjCA,KAAK,0BAA0B,GAC7B;oCACI,GAAGA,KAAK,0BAA0B,EAAE;oCACpC,GAAGA,KAAK,0BAA0B,CAAC,EAAE,CAAC;iCACzC,GACD,EAAE;6BACX;wBACL;wBACA;4BACI,KAAK;4BACL,QAAQ;4BACR,QAAQ;gCACJ;gCACA;gCACA;gCACA;gCACA;gCACA;6BACH;4BACD,UAAU;gCACNlB,0CAAAA,WAAkB,CAAC,aAAa,EAAEkB,KAAK,mBAAmB,CAAC,CAAC;gCAC5DlB,0CAAAA,WAAkB,CAAC,aAAa,EAAEkB,KAAK,mBAAmB,CAAC,EAAE,CAAC;6BACjE;wBACL;wBACA;4BACI,KAAK;4BACL,QAAQ;4BACR,QAAQ;gCAAC;6BAAwB;4BACjC,UAAUlB,0CAAAA,WAAkB,CAAC,eAAe,EAAEgB,UAAU,CAAC,EAAEF,aAAa,WAAW,CAAC;wBACxF;wBACA;4BACI,KAAK;4BACL,QAAQ;4BACR,QAAQ;4BACR,UAAU,GAAGI,KAAK,kBAAkB,EAAE;wBAC1C;wBACA;4BACI,KAAK;4BACL,QAAQ;4BACR,QAAQ;4BACR,UAAUA,KAAK,WAAW;wBAC9B;wBACA;4BACI,KAAK;4BACL,QAAQ;4BACR,QAAQ;4BACR,UAAUlB,0CAAAA,WAAkB,CAAC,oBAAoB,EAAEc,aAAa,eAAe,CAAC;wBACpF;2BAEII,KAAK,mBAAmB,GACtB;4BACI;gCACI,KAAK;gCACL,QAAQ;gCACR,QAAQ;gCACR,UAAU;oCACN,GAAGA,KAAK,mBAAmB,EAAE;oCAC7B,GAAGA,KAAK,mBAAmB,CAAC,EAAE,CAAC;iCAClC;4BACL;yBACH,GACD,EAAE;qBACX;gBACL;gBAEA,OAAOzB;YACX;QACJ;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"pulumi/apps/api/ApiGraphql.js","sources":["../../../../src/pulumi/apps/api/ApiGraphql.ts"],"sourcesContent":["import path from \"path\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as aws from \"@pulumi/aws\";\nimport type { PulumiApp, PulumiAppModule } from \"@webiny/pulumi\";\nimport { createAppModule } from \"@webiny/pulumi\";\nimport { createLambdaRole, getCommonLambdaEnvVariables } from \"../lambdaUtils.js\";\nimport { CoreOutput, VpcConfig } from \"~/pulumi/apps/index.js\";\nimport { getAwsAccountId, getAwsRegion } from \"../awsUtils.js\";\nimport { LAMBDA_RUNTIME } from \"~/pulumi/constants.js\";\nimport { ApiGraphqlWeb } from \"./ApiGraphqlWeb.js\";\nimport { isRouteNameAllowed } from \"./isRouteNameAllowed.js\";\n\ninterface GraphqlParams {\n env: Record<string, any>;\n}\n\nexport interface AddRouteParams {\n /**\n * Must be in kebab case (a-z, 0-9 and -) when the route goes to API Gateway.\n */\n name: string;\n path: `/${string}`;\n method: \"DELETE\" | \"GET\" | \"HEAD\" | \"PATCH\" | \"POST\" | \"PUT\" | \"OPTIONS\" | \"ANY\";\n}\n\nconst EMPTY_TRASH_BIN_EVENT_RULE_NAME = `empty-trash-bin-event-rule`;\nconst EMPTY_TRASH_BIN_EVENT_PERMISSION_NAME = `empty-trash-bin-event-target-permission`;\nconst EMPTY_TRASH_BIN_EVENT_RULE_TARGET = `empty-trash-bin-event-rule-target`;\n\nexport type ApiGraphql = PulumiAppModule<typeof ApiGraphql>;\n\nexport const ApiGraphql = createAppModule({\n name: \"ApiGraphql\",\n config(app: PulumiApp, params: GraphqlParams) {\n const policy = createGraphqlLambdaPolicy(app);\n const role = createLambdaRole(app, {\n name: \"api-lambda-role\",\n policy: policy.output\n });\n\n const graphql = app.addResource(aws.lambda.Function, {\n name: \"graphql\",\n config: {\n description: \"Webiny's GraphQL APIs\",\n runtime: LAMBDA_RUNTIME,\n handler: \"handler.handler\",\n role: role.output.arn,\n timeout: 30,\n memorySize: 1024,\n code: new pulumi.asset.AssetArchive({\n \".\": new pulumi.asset.FileArchive(\n path.join(app.paths.workspace, \"graphql/build\")\n )\n }),\n environment: {\n variables: getCommonLambdaEnvVariables().apply(value => ({\n ...value,\n ...params.env,\n AWS_NODEJS_CONNECTION_REUSE_ENABLED: \"1\"\n }))\n },\n vpcConfig: app.getModule(VpcConfig).functionVpcConfig,\n loggingConfig: {\n logFormat: \"JSON\"\n }\n }\n });\n\n // Create event rule.\n const eventRule = app.addResource(aws.cloudwatch.EventRule, {\n name: EMPTY_TRASH_BIN_EVENT_RULE_NAME,\n config: {\n description: \"Enable us to empty the trash-bin ever day\",\n scheduleExpression: \"cron(0 3 * * ? *)\"\n }\n });\n\n // Add required permission to the target lambda.\n app.addResource(aws.lambda.Permission, {\n name: EMPTY_TRASH_BIN_EVENT_PERMISSION_NAME,\n config: {\n action: \"lambda:InvokeFunction\",\n function: graphql.output.arn,\n principal: \"events.amazonaws.com\",\n statementId: \"allow-rule-invoke-\" + EMPTY_TRASH_BIN_EVENT_RULE_NAME\n }\n });\n\n // Target the main graphql lambda.\n app.addResource(aws.cloudwatch.EventTarget, {\n name: EMPTY_TRASH_BIN_EVENT_RULE_TARGET,\n config: {\n rule: eventRule.output.name,\n arn: graphql.output.arn,\n input: JSON.stringify({\n source: \"webiny.events\",\n \"detail-type\": \"WebinyEmptyTrashBin\"\n })\n }\n });\n\n return {\n role,\n policy,\n functions: {\n graphql\n },\n addRoute: (routeParams: AddRouteParams) => {\n // With the web function there is no HTTP API Gateway: the route goes to the web\n // function, whose router matches the method. The name isn't used here, so it isn't\n // checked either.\n const graphqlWeb = app.getModule(ApiGraphqlWeb, { optional: true });\n if (graphqlWeb) {\n graphqlWeb.addRoute(routeParams.path);\n return;\n }\n\n if (!isRouteNameAllowed(routeParams.name)) {\n console.log(`Route name is not allowed: \"${routeParams.name}\".`);\n return;\n }\n\n const apiGateway: any = app.resources.apiGateway;\n if (!apiGateway) {\n console.log(\n \"Could not add route because there is no apiGateway in the resources.\"\n );\n return;\n }\n return apiGateway.addRoute(routeParams.name, {\n path: routeParams.path,\n method: routeParams.method,\n function: graphql.output.arn\n });\n }\n };\n }\n});\n\nfunction createGraphqlLambdaPolicy(app: PulumiApp) {\n const coreOutput = app.getModule(CoreOutput);\n const awsAccountId = getAwsAccountId(app);\n const awsRegion = getAwsRegion(app);\n\n return app.addResource(aws.iam.Policy, {\n name: \"ApiGraphqlLambdaPolicy\",\n config: {\n description: \"This policy enables access to Dynamodb, S3, Lambda and Cognito IDP\",\n // Core is pulumi.Output, so we need to run apply() to resolve policy based on it\n policy: pulumi.all([coreOutput]).apply(([core]) => {\n const policy: aws.iam.PolicyDocument = {\n Version: \"2012-10-17\",\n Statement: [\n // The core's DynamoDB tables: only the OpenSearch one, if any, with\n // `<Infra.AuroraPostgres />`.\n ...createDynamoDbStatements(core),\n {\n Sid: \"PermissionForS3\",\n Effect: \"Allow\",\n Action: [\n \"s3:ListBucket\",\n \"s3:GetObjectAcl\",\n \"s3:DeleteObject\",\n \"s3:PutObjectAcl\",\n \"s3:PutObject\",\n \"s3:GetObject\"\n ],\n Resource: [\n pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}`,\n pulumi.interpolate`arn:aws:s3:::${core.fileManagerBucketId}/*`\n ]\n },\n {\n Sid: \"PermissionForLambda\",\n Effect: \"Allow\",\n Action: [\"lambda:InvokeFunction\"],\n Resource: pulumi.interpolate`arn:aws:lambda:${awsRegion}:${awsAccountId}:function:*`\n },\n {\n Sid: \"PermissionForCognitoIdp\",\n Effect: \"Allow\",\n Action: \"cognito-idp:*\",\n Resource: `${core.cognitoUserPoolArn}`\n },\n {\n Sid: \"PermissionForEventBus\",\n Effect: \"Allow\",\n Action: \"events:PutEvents\",\n Resource: core.eventBusArn\n },\n {\n Sid: \"PermissionForCloudfront\",\n Effect: \"Allow\",\n Action: \"cloudfront:CreateInvalidation\",\n Resource: pulumi.interpolate`arn:aws:cloudfront::${awsAccountId}:distribution/*`\n },\n // Attach permissions for elastic search domain as well (if ES is enabled).\n ...(core.opensearchDomainArn\n ? [\n {\n Sid: \"PermissionForOS\",\n Effect: \"Allow\" as const,\n Action: \"es:*\",\n Resource: [\n `${core.opensearchDomainArn}`,\n `${core.opensearchDomainArn}/*`\n ]\n }\n ]\n : [])\n ]\n };\n\n return policy;\n })\n }\n });\n}\n\n/*\n * Every DynamoDB action on the core's tables that exist: the primary and audit logs ones (none with\n * `<Infra.AuroraPostgres />`) and the OpenSearch one (with OpenSearch). No statement without\n * tables.\n */\nfunction createDynamoDbStatements(core: {\n primaryDynamodbTableArn: string | undefined;\n auditLogsDynamodbTableArn: string | undefined;\n opensearchDynamodbTableArn: string | undefined;\n}): aws.iam.PolicyStatement[] {\n const tableArns = [\n core.primaryDynamodbTableArn,\n core.auditLogsDynamodbTableArn,\n core.opensearchDynamodbTableArn\n ].filter((arn): arn is string => Boolean(arn));\n\n if (!tableArns.length) {\n return [];\n }\n\n return [\n {\n Sid: \"PermissionForDynamodb\",\n Effect: \"Allow\",\n Action: [\n \"dynamodb:BatchGetItem\",\n \"dynamodb:BatchWriteItem\",\n \"dynamodb:ConditionCheckItem\",\n \"dynamodb:CreateBackup\",\n \"dynamodb:CreateTable\",\n \"dynamodb:CreateTableReplica\",\n \"dynamodb:DeleteBackup\",\n \"dynamodb:DeleteItem\",\n \"dynamodb:DeleteTable\",\n \"dynamodb:DeleteTableReplica\",\n \"dynamodb:DescribeBackup\",\n \"dynamodb:DescribeContinuousBackups\",\n \"dynamodb:DescribeContributorInsights\",\n \"dynamodb:DescribeExport\",\n \"dynamodb:DescribeKinesisStreamingDestination\",\n \"dynamodb:DescribeLimits\",\n \"dynamodb:DescribeReservedCapacity\",\n \"dynamodb:DescribeReservedCapacityOfferings\",\n \"dynamodb:DescribeStream\",\n \"dynamodb:DescribeTable\",\n \"dynamodb:DescribeTableReplicaAutoScaling\",\n \"dynamodb:DescribeTimeToLive\",\n \"dynamodb:DisableKinesisStreamingDestination\",\n \"dynamodb:EnableKinesisStreamingDestination\",\n \"dynamodb:ExportTableToPointInTime\",\n \"dynamodb:GetItem\",\n \"dynamodb:GetRecords\",\n \"dynamodb:GetShardIterator\",\n \"dynamodb:ListBackups\",\n \"dynamodb:ListContributorInsights\",\n \"dynamodb:ListExports\",\n \"dynamodb:ListStreams\",\n \"dynamodb:ListTables\",\n \"dynamodb:ListTagsOfResource\",\n \"dynamodb:PartiQLDelete\",\n \"dynamodb:PartiQLInsert\",\n \"dynamodb:PartiQLSelect\",\n \"dynamodb:PartiQLUpdate\",\n \"dynamodb:PurchaseReservedCapacityOfferings\",\n \"dynamodb:PutItem\",\n \"dynamodb:Query\",\n \"dynamodb:RestoreTableFromBackup\",\n \"dynamodb:RestoreTableToPointInTime\",\n \"dynamodb:Scan\",\n \"dynamodb:UpdateContinuousBackups\",\n \"dynamodb:UpdateContributorInsights\",\n \"dynamodb:UpdateItem\",\n \"dynamodb:UpdateTable\",\n \"dynamodb:UpdateTableReplicaAutoScaling\",\n \"dynamodb:UpdateTimeToLive\"\n ],\n Resource: tableArns.flatMap(arn => [arn, `${arn}/*`])\n }\n ];\n}\n"],"names":["EMPTY_TRASH_BIN_EVENT_RULE_NAME","EMPTY_TRASH_BIN_EVENT_PERMISSION_NAME","EMPTY_TRASH_BIN_EVENT_RULE_TARGET","ApiGraphql","createAppModule","app","params","policy","createGraphqlLambdaPolicy","role","createLambdaRole","graphql","aws","LAMBDA_RUNTIME","pulumi","path","getCommonLambdaEnvVariables","value","VpcConfig","eventRule","JSON","routeParams","graphqlWeb","ApiGraphqlWeb","isRouteNameAllowed","console","apiGateway","coreOutput","CoreOutput","awsAccountId","getAwsAccountId","awsRegion","getAwsRegion","core","createDynamoDbStatements","tableArns","arn","Boolean"],"mappings":";;;;;;;;;;AAyBA,MAAMA,kCAAkC;AACxC,MAAMC,wCAAwC;AAC9C,MAAMC,oCAAoC;AAInC,MAAMC,aAAaC,gBAAgB;IACtC,MAAM;IACN,QAAOC,GAAc,EAAEC,MAAqB;QACxC,MAAMC,SAASC,0BAA0BH;QACzC,MAAMI,OAAOC,iBAAiBL,KAAK;YAC/B,MAAM;YACN,QAAQE,OA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,UAAUA,UAAU,OAAO,CAACC,CAAAA,MAAO;oBAACA;oBAAK,GAAGA,IAAI,EAAE,CAAC;iBAAC;QACxD;KACH;AACL"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
2
|
+
import type { PulumiAppModule } from "@webiny/pulumi";
|
|
3
|
+
export interface GraphqlWebVpc {
|
|
4
|
+
subnetIds: pulumi.Input<pulumi.Input<string>[]>;
|
|
5
|
+
securityGroupIds: pulumi.Input<pulumi.Input<string>[]>;
|
|
6
|
+
}
|
|
7
|
+
interface GraphqlWebParams {
|
|
8
|
+
/**
|
|
9
|
+
* The project's Pulumi resource name prefix, so the function's name carries it like the other
|
|
10
|
+
* resources' names do.
|
|
11
|
+
*/
|
|
12
|
+
namePrefix: string;
|
|
13
|
+
/**
|
|
14
|
+
* The subnets and security groups the regular Lambdas use, when the project has a VPC. The web
|
|
15
|
+
* function reaches them through an egress network connector.
|
|
16
|
+
*/
|
|
17
|
+
vpc: GraphqlWebVpc | null;
|
|
18
|
+
/**
|
|
19
|
+
* Env for the web function only, on top of the `graphql` Lambda's (and over it, for a variable
|
|
20
|
+
* both have). The `graphql` Lambda and the functions that copy its env don't get it.
|
|
21
|
+
*/
|
|
22
|
+
env?: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
export type ApiGraphqlWeb = PulumiAppModule<typeof ApiGraphqlWeb>;
|
|
25
|
+
/**
|
|
26
|
+
* Serves the API's HTTP routes from a Lambda web function. On by default;
|
|
27
|
+
* `<Infra.Api.WebFunction enabled={false} />` turns it off.
|
|
28
|
+
*
|
|
29
|
+
* A web function runs `build-web/index.mjs` as a plain Node HTTP server. It only serves HTTP, so the
|
|
30
|
+
* `graphql` Lambda stays: background tasks, EventBridge rules, EventBridge Scheduler and the WebSocket
|
|
31
|
+
* API still invoke it. CloudFront reaches the endpoint through an OAC, and the resource policy that
|
|
32
|
+
* lets it do so is created in ApiCloudfront, because it needs the distribution's ARN. With a VPC, the
|
|
33
|
+
* function's outbound traffic goes through an egress network connector into the same subnets the
|
|
34
|
+
* regular Lambdas use.
|
|
35
|
+
*/
|
|
36
|
+
export declare const ApiGraphqlWeb: import("@webiny/pulumi").PulumiAppModuleDefinition<{
|
|
37
|
+
fn: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/lambdaweb/function.js").Function>;
|
|
38
|
+
revision: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/lambdaweb/functionRevision.js").FunctionRevision>;
|
|
39
|
+
endpoint: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/lambdaweb/functionEndpoint.js").FunctionEndpoint>;
|
|
40
|
+
codeBucket: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/s3/bucket.js").Bucket>;
|
|
41
|
+
logGroup: import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/cloudwatch/logGroup.js").LogGroup>;
|
|
42
|
+
addRoute(routePath: string): void;
|
|
43
|
+
onRoute(listener: (routePath: string) => void): void;
|
|
44
|
+
}, GraphqlWebParams>;
|
|
45
|
+
export {};
|