@stacksjs/cloud 0.59.10 → 0.61.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/dist/index.js +843 -754
- package/package.json +30 -30
- package/src/cloud/ai.ts +5 -12
- package/src/cloud/aws-sdk-layer/nodejs/package-lock.json +8 -6
- package/src/cloud/aws-sdk-layer/nodejs/package.json +2 -2
- package/src/cloud/cdn.ts +41 -20
- package/src/cloud/cli.ts +1 -3
- package/src/cloud/compute.ts +39 -17
- package/src/cloud/dashboard.ts +0 -1
- package/src/cloud/database.ts +34 -0
- package/src/cloud/deployment.ts +8 -7
- package/src/cloud/dns.ts +0 -1
- package/src/cloud/docs.ts +3 -4
- package/src/cloud/email.ts +57 -40
- package/src/cloud/index.ts +9 -9
- package/src/cloud/jump-box.ts +0 -1
- package/src/cloud/lambda/ask/{index.js → index.cjs} +16 -15
- package/src/cloud/lambda/summarize/index.cjs +36 -0
- package/src/cloud/permissions.ts +3 -3
- package/src/cloud/queue.ts +73 -53
- package/src/cloud/redirects.ts +11 -4
- package/src/cloud/router-layer/nodejs/package.json +2 -2
- package/src/cloud/security.ts +19 -11
- package/src/edge/origin-request.ts +2 -1
- package/src/helpers.ts +147 -132
- package/dist/cloud/ai.d.ts +0 -10
- package/dist/cloud/cdn.d.ts +0 -44
- package/dist/cloud/cli.d.ts +0 -9
- package/dist/cloud/compute.d.ts +0 -17
- package/dist/cloud/deployment.d.ts +0 -14
- package/dist/cloud/dns.d.ts +0 -7
- package/dist/cloud/docs.d.ts +0 -9
- package/dist/cloud/email.d.ts +0 -10
- package/dist/cloud/file-system.d.ts +0 -12
- package/dist/cloud/index.d.ts +0 -41
- package/dist/cloud/jump-box.d.ts +0 -12
- package/dist/cloud/network.d.ts +0 -9
- package/dist/cloud/permissions.d.ts +0 -7
- package/dist/cloud/queue.d.ts +0 -24
- package/dist/cloud/redirects.d.ts +0 -9
- package/dist/cloud/security.d.ts +0 -14
- package/dist/cloud/storage.d.ts +0 -18
- package/dist/edge/origin-request.d.ts +0 -1
- package/dist/helpers.d.ts +0 -67
- package/dist/index.d.ts +0 -2
- package/dist/types.d.ts +0 -26
- package/src/cloud/lambda/summarize/index.js +0 -35
- /package/src/cloud/lambda/cli-setup/{index.js → index.cjs} +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/cloud",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.61.0",
|
|
5
5
|
"description": "The Stacks cloud/serverless integration & implementation.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"license": "MIT",
|
|
@@ -53,19 +53,19 @@
|
|
|
53
53
|
"prepublishOnly": "bun run build"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@aws-sdk/client-bedrock": "^3.
|
|
57
|
-
"@aws-sdk/client-cloudformation": "^3.
|
|
58
|
-
"@aws-sdk/client-cloudfront": "^3.
|
|
59
|
-
"@aws-sdk/client-cloudwatch-logs": "^3.
|
|
60
|
-
"@aws-sdk/client-ec2": "^3.
|
|
61
|
-
"@aws-sdk/client-efs": "^3.
|
|
62
|
-
"@aws-sdk/client-iam": "^3.
|
|
63
|
-
"@aws-sdk/client-lambda": "^3.
|
|
64
|
-
"@aws-sdk/client-route-53-domains": "^3.
|
|
65
|
-
"@aws-sdk/client-s3": "^3.
|
|
66
|
-
"@aws-sdk/client-ses": "^3.
|
|
67
|
-
"@aws-sdk/client-sesv2": "^3.
|
|
68
|
-
"@aws-sdk/client-ssm": "^3.
|
|
56
|
+
"@aws-sdk/client-bedrock": "^3.577.0",
|
|
57
|
+
"@aws-sdk/client-cloudformation": "^3.577.0",
|
|
58
|
+
"@aws-sdk/client-cloudfront": "^3.577.0",
|
|
59
|
+
"@aws-sdk/client-cloudwatch-logs": "^3.577.0",
|
|
60
|
+
"@aws-sdk/client-ec2": "^3.577.0",
|
|
61
|
+
"@aws-sdk/client-efs": "^3.577.0",
|
|
62
|
+
"@aws-sdk/client-iam": "^3.577.0",
|
|
63
|
+
"@aws-sdk/client-lambda": "^3.577.0",
|
|
64
|
+
"@aws-sdk/client-route-53-domains": "^3.577.0",
|
|
65
|
+
"@aws-sdk/client-s3": "^3.577.0",
|
|
66
|
+
"@aws-sdk/client-ses": "^3.577.0",
|
|
67
|
+
"@aws-sdk/client-sesv2": "^3.577.0",
|
|
68
|
+
"@aws-sdk/client-ssm": "^3.577.0",
|
|
69
69
|
"@stacksjs/cli": "latest",
|
|
70
70
|
"@stacksjs/config": "latest",
|
|
71
71
|
"@stacksjs/env": "latest",
|
|
@@ -78,20 +78,20 @@
|
|
|
78
78
|
"@stacksjs/validation": "latest"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@aws-sdk/client-bedrock": "^3.
|
|
82
|
-
"@aws-sdk/client-cloudformation": "^3.
|
|
83
|
-
"@aws-sdk/client-cloudfront": "^3.
|
|
84
|
-
"@aws-sdk/client-cloudwatch-logs": "^3.
|
|
85
|
-
"@aws-sdk/client-dynamodb": "3.
|
|
86
|
-
"@aws-sdk/client-ec2": "^3.
|
|
87
|
-
"@aws-sdk/client-efs": "^3.
|
|
88
|
-
"@aws-sdk/client-iam": "^3.
|
|
89
|
-
"@aws-sdk/client-lambda": "^3.
|
|
90
|
-
"@aws-sdk/client-route-53-domains": "^3.
|
|
91
|
-
"@aws-sdk/client-s3": "^3.
|
|
92
|
-
"@aws-sdk/client-ses": "^3.
|
|
93
|
-
"@aws-sdk/client-sesv2": "^3.
|
|
94
|
-
"@aws-sdk/client-ssm": "^3.
|
|
81
|
+
"@aws-sdk/client-bedrock": "^3.577.0",
|
|
82
|
+
"@aws-sdk/client-cloudformation": "^3.577.0",
|
|
83
|
+
"@aws-sdk/client-cloudfront": "^3.577.0",
|
|
84
|
+
"@aws-sdk/client-cloudwatch-logs": "^3.577.0",
|
|
85
|
+
"@aws-sdk/client-dynamodb": "3.577.0",
|
|
86
|
+
"@aws-sdk/client-ec2": "^3.577.0",
|
|
87
|
+
"@aws-sdk/client-efs": "^3.577.0",
|
|
88
|
+
"@aws-sdk/client-iam": "^3.577.0",
|
|
89
|
+
"@aws-sdk/client-lambda": "^3.577.0",
|
|
90
|
+
"@aws-sdk/client-route-53-domains": "^3.577.0",
|
|
91
|
+
"@aws-sdk/client-s3": "^3.577.0",
|
|
92
|
+
"@aws-sdk/client-ses": "^3.577.0",
|
|
93
|
+
"@aws-sdk/client-sesv2": "^3.577.0",
|
|
94
|
+
"@aws-sdk/client-ssm": "^3.577.0",
|
|
95
95
|
"@stacksjs/config": "latest",
|
|
96
96
|
"@stacksjs/dns": "latest",
|
|
97
97
|
"@stacksjs/env": "latest",
|
|
@@ -101,8 +101,8 @@
|
|
|
101
101
|
"@stacksjs/storage": "latest",
|
|
102
102
|
"@stacksjs/utils": "latest",
|
|
103
103
|
"@stacksjs/validation": "latest",
|
|
104
|
-
"aws-cdk": "^2.
|
|
105
|
-
"aws-cdk-lib": "^2.
|
|
104
|
+
"aws-cdk": "^2.142.1",
|
|
105
|
+
"aws-cdk-lib": "^2.142.1",
|
|
106
106
|
"aws4fetch": "^1.0.18",
|
|
107
107
|
"constructs": "^10.3.0"
|
|
108
108
|
},
|
package/src/cloud/ai.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { config } from '@stacksjs/config'
|
|
2
2
|
import { Duration, CfnOutput as Output, aws_iam as iam, aws_lambda as lambda } from 'aws-cdk-lib'
|
|
3
3
|
import type { Construct } from 'constructs'
|
|
4
|
-
import { config } from '@stacksjs/config'
|
|
5
4
|
import type { NestedCloudProps } from '../types'
|
|
6
5
|
|
|
7
|
-
export interface AiStackProps extends NestedCloudProps {
|
|
8
|
-
}
|
|
6
|
+
export interface AiStackProps extends NestedCloudProps {}
|
|
9
7
|
|
|
10
8
|
export class AiStack {
|
|
11
9
|
askAiUrl: lambda.FunctionUrl
|
|
@@ -21,18 +19,13 @@ export class AiStack {
|
|
|
21
19
|
|
|
22
20
|
const bedrockAccessPolicy = new iam.PolicyStatement({
|
|
23
21
|
effect: iam.Effect.ALLOW,
|
|
24
|
-
actions: [
|
|
25
|
-
|
|
26
|
-
'bedrock:InvokeModelWithResponseStream',
|
|
27
|
-
],
|
|
28
|
-
resources: config.ai.models?.map(model => `arn:aws:bedrock:us-east-1::foundation-model/${model}`),
|
|
22
|
+
actions: ['bedrock:InvokeModel', 'bedrock:InvokeModelWithResponseStream'],
|
|
23
|
+
resources: config.ai.models?.map((model) => `arn:aws:bedrock:us-east-1::foundation-model/${model}`),
|
|
29
24
|
})
|
|
30
25
|
|
|
31
26
|
const bedrockAccessRole = new iam.Role(scope, 'BedrockAccessRole', {
|
|
32
27
|
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
|
|
33
|
-
managedPolicies: [
|
|
34
|
-
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole'),
|
|
35
|
-
],
|
|
28
|
+
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole')],
|
|
36
29
|
})
|
|
37
30
|
|
|
38
31
|
bedrockAccessRole.addToPolicy(bedrockAccessPolicy)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aws-sdk-layer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.3",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "aws-sdk-layer",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.60.3",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"aws-sdk": "^2.
|
|
12
|
+
"aws-sdk": "^2.1624.0"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"node_modules/available-typed-arrays": {
|
|
@@ -24,9 +24,11 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"node_modules/aws-sdk": {
|
|
27
|
-
"version": "2.
|
|
28
|
-
"resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.
|
|
29
|
-
"integrity": "sha512-
|
|
27
|
+
"version": "2.1624.0",
|
|
28
|
+
"resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1624.0.tgz",
|
|
29
|
+
"integrity": "sha512-SxBGDkdmsQTXLKPaY+hLqjlQyZBaGaFD34EhTd4aYuuqT952sxYeDt7w75py4o4O5z4hUUTccqTF9dtpxCPJfg==",
|
|
30
|
+
"hasInstallScript": true,
|
|
31
|
+
"license": "Apache-2.0",
|
|
30
32
|
"dependencies": {
|
|
31
33
|
"buffer": "4.9.2",
|
|
32
34
|
"events": "1.1.1",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aws-sdk-layer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.61.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"aws-sdk": "^2.
|
|
13
|
+
"aws-sdk": "^2.1624.0"
|
|
14
14
|
}
|
|
15
15
|
}
|
package/src/cloud/cdn.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
/* eslint-disable no-new */
|
|
2
|
-
import type { aws_certificatemanager as acm, aws_lambda as lambda, aws_s3 as s3, aws_wafv2 as wafv2 } from 'aws-cdk-lib'
|
|
3
|
-
import { Duration, Fn, CfnOutput as Output, aws_cloudfront as cloudfront, aws_cloudfront_origins as origins, aws_route53 as route53, aws_route53_targets as targets } from 'aws-cdk-lib'
|
|
4
|
-
import type { Construct } from 'constructs'
|
|
5
1
|
import { config } from '@stacksjs/config'
|
|
6
|
-
import { hasFiles } from '@stacksjs/storage'
|
|
7
|
-
import { path as p } from '@stacksjs/path'
|
|
8
2
|
import { env } from '@stacksjs/env'
|
|
3
|
+
import { path as p } from '@stacksjs/path'
|
|
4
|
+
import { hasFiles } from '@stacksjs/storage'
|
|
5
|
+
import type { aws_certificatemanager as acm, aws_lambda as lambda, aws_s3 as s3, aws_wafv2 as wafv2 } from 'aws-cdk-lib'
|
|
6
|
+
import {
|
|
7
|
+
Duration,
|
|
8
|
+
Fn,
|
|
9
|
+
CfnOutput as Output,
|
|
10
|
+
aws_cloudfront as cloudfront,
|
|
11
|
+
aws_cloudfront_origins as origins,
|
|
12
|
+
aws_route53 as route53,
|
|
13
|
+
aws_route53_targets as targets,
|
|
14
|
+
} from 'aws-cdk-lib'
|
|
9
15
|
import type { ApplicationLoadBalancer } from 'aws-cdk-lib/aws-elasticloadbalancingv2'
|
|
10
16
|
import * as kinesis from 'aws-cdk-lib/aws-kinesis'
|
|
11
|
-
import type {
|
|
17
|
+
import type { Construct } from 'constructs'
|
|
12
18
|
import type { EnvKey } from '../../../../env'
|
|
19
|
+
import type { NestedCloudProps } from '../types'
|
|
13
20
|
|
|
14
21
|
export interface CdnStackProps extends NestedCloudProps {
|
|
15
22
|
certificate: acm.Certificate
|
|
@@ -74,9 +81,7 @@ export class CdnStack {
|
|
|
74
81
|
|
|
75
82
|
// TODO: make this configurable
|
|
76
83
|
this.realtimeLogConfig = new cloudfront.RealtimeLogConfig(scope, 'StacksRealTimeLogConfig', {
|
|
77
|
-
endPoints: [
|
|
78
|
-
cloudfront.Endpoint.fromKinesisStream(logStream),
|
|
79
|
-
],
|
|
84
|
+
endPoints: [cloudfront.Endpoint.fromKinesisStream(logStream)],
|
|
80
85
|
fields: [
|
|
81
86
|
'timestamp',
|
|
82
87
|
'c-ip',
|
|
@@ -169,7 +174,7 @@ export class CdnStack {
|
|
|
169
174
|
return cloudfront.CacheCookieBehavior.none()
|
|
170
175
|
case 'allowList':
|
|
171
176
|
// If you have a list of cookies, replace `myCookie` with your cookie
|
|
172
|
-
return cloudfront.CacheCookieBehavior.allowList(...config.cloud.cdn?.allowList.cookies || [])
|
|
177
|
+
return cloudfront.CacheCookieBehavior.allowList(...(config.cloud.cdn?.allowList.cookies || []))
|
|
173
178
|
default:
|
|
174
179
|
return undefined
|
|
175
180
|
}
|
|
@@ -200,8 +205,7 @@ export class CdnStack {
|
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
allowedMethodsFromString(methods?: 'ALL' | 'GET_HEAD' | 'GET_HEAD_OPTIONS'): cloudfront.AllowedMethods {
|
|
203
|
-
if (!methods)
|
|
204
|
-
return cloudfront.AllowedMethods.ALLOW_ALL
|
|
208
|
+
if (!methods) return cloudfront.AllowedMethods.ALLOW_ALL
|
|
205
209
|
|
|
206
210
|
switch (methods) {
|
|
207
211
|
case 'ALL':
|
|
@@ -216,8 +220,7 @@ export class CdnStack {
|
|
|
216
220
|
}
|
|
217
221
|
|
|
218
222
|
cachedMethodsFromString(methods?: 'GET_HEAD' | 'GET_HEAD_OPTIONS'): cloudfront.CachedMethods {
|
|
219
|
-
if (!methods)
|
|
220
|
-
return cloudfront.CachedMethods.CACHE_GET_HEAD
|
|
223
|
+
if (!methods) return cloudfront.CachedMethods.CACHE_GET_HEAD
|
|
221
224
|
|
|
222
225
|
switch (methods) {
|
|
223
226
|
case 'GET_HEAD':
|
|
@@ -230,7 +233,7 @@ export class CdnStack {
|
|
|
230
233
|
}
|
|
231
234
|
|
|
232
235
|
shouldDeployApi() {
|
|
233
|
-
return config.
|
|
236
|
+
return config.api?.deploy
|
|
234
237
|
}
|
|
235
238
|
|
|
236
239
|
apiBehaviorOptions(scope: Construct, props: CdnStackProps): Record<string, cloudfront.BehaviorOptions> {
|
|
@@ -376,8 +379,27 @@ export class CdnStack {
|
|
|
376
379
|
let behaviorOptions: Record<string, cloudfront.BehaviorOptions> = {}
|
|
377
380
|
|
|
378
381
|
if (this.shouldDeployApi()) {
|
|
379
|
-
const keysToRemove = [
|
|
380
|
-
|
|
382
|
+
const keysToRemove = [
|
|
383
|
+
'_HANDLER',
|
|
384
|
+
'_X_AMZN_TRACE_ID',
|
|
385
|
+
'AWS_REGION',
|
|
386
|
+
'AWS_EXECUTION_ENV',
|
|
387
|
+
'AWS_LAMBDA_FUNCTION_NAME',
|
|
388
|
+
'AWS_LAMBDA_FUNCTION_MEMORY_SIZE',
|
|
389
|
+
'AWS_LAMBDA_FUNCTION_VERSION',
|
|
390
|
+
'AWS_LAMBDA_INITIALIZATION_TYPE',
|
|
391
|
+
'AWS_LAMBDA_LOG_GROUP_NAME',
|
|
392
|
+
'AWS_LAMBDA_LOG_STREAM_NAME',
|
|
393
|
+
'AWS_ACCESS_KEY',
|
|
394
|
+
'AWS_ACCESS_KEY_ID',
|
|
395
|
+
'AWS_SECRET_ACCESS_KEY',
|
|
396
|
+
'AWS_SESSION_TOKEN',
|
|
397
|
+
'AWS_LAMBDA_RUNTIME_API',
|
|
398
|
+
'LAMBDA_TASK_ROOT',
|
|
399
|
+
'LAMBDA_RUNTIME_DIR',
|
|
400
|
+
'_',
|
|
401
|
+
]
|
|
402
|
+
keysToRemove.forEach((key) => delete env[key as EnvKey])
|
|
381
403
|
|
|
382
404
|
behaviorOptions = this.apiBehaviorOptions(scope, props)
|
|
383
405
|
}
|
|
@@ -409,8 +431,7 @@ export class CdnStack {
|
|
|
409
431
|
}
|
|
410
432
|
|
|
411
433
|
setApiCachePolicy(scope: Construct) {
|
|
412
|
-
if (this.apiCachePolicy)
|
|
413
|
-
return this.apiCachePolicy
|
|
434
|
+
if (this.apiCachePolicy) return this.apiCachePolicy
|
|
414
435
|
|
|
415
436
|
this.apiCachePolicy = new cloudfront.CachePolicy(scope, 'ApiCachePolicy', {
|
|
416
437
|
comment: 'Stacks API Cache Policy',
|
package/src/cloud/cli.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
/* eslint-disable no-new */
|
|
2
1
|
import { Duration, CfnOutput as Output, aws_lambda as lambda } from 'aws-cdk-lib'
|
|
3
2
|
import type { Construct } from 'constructs'
|
|
4
3
|
import type { NestedCloudProps } from '../types'
|
|
5
4
|
|
|
6
|
-
export interface CliStackProps extends NestedCloudProps {
|
|
7
|
-
}
|
|
5
|
+
export interface CliStackProps extends NestedCloudProps {}
|
|
8
6
|
|
|
9
7
|
export class CliStack {
|
|
10
8
|
cliSetupUrl: lambda.FunctionUrl
|
package/src/cloud/compute.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
/* eslint-disable no-new */
|
|
2
|
-
import type { aws_certificatemanager as acm, aws_efs as efs } from 'aws-cdk-lib'
|
|
3
|
-
import { Duration, CfnOutput as Output, RemovalPolicy, aws_ec2 as ec2, aws_ecs as ecs, aws_route53 as route53, aws_route53_targets as route53Targets, aws_secretsmanager as secretsmanager } from 'aws-cdk-lib'
|
|
4
|
-
import type { Construct } from 'constructs'
|
|
5
|
-
import { path as p } from '@stacksjs/path'
|
|
6
1
|
import { env } from '@stacksjs/env'
|
|
7
|
-
import {
|
|
2
|
+
import { path as p } from '@stacksjs/path'
|
|
3
|
+
import type { aws_certificatemanager as acm, aws_efs as efs } from 'aws-cdk-lib'
|
|
4
|
+
import {
|
|
5
|
+
Duration,
|
|
6
|
+
CfnOutput as Output,
|
|
7
|
+
RemovalPolicy,
|
|
8
|
+
aws_ec2 as ec2,
|
|
9
|
+
aws_ecs as ecs,
|
|
10
|
+
aws_route53 as route53,
|
|
11
|
+
aws_route53_targets as route53Targets,
|
|
12
|
+
aws_secretsmanager as secretsmanager,
|
|
13
|
+
} from 'aws-cdk-lib'
|
|
8
14
|
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2'
|
|
9
|
-
import
|
|
15
|
+
import { LogGroup } from 'aws-cdk-lib/aws-logs'
|
|
16
|
+
import type { Construct } from 'constructs'
|
|
10
17
|
import type { EnvKey } from '../../../../env'
|
|
18
|
+
import type { NestedCloudProps } from '../types'
|
|
11
19
|
|
|
12
20
|
export interface ComputeStackProps extends NestedCloudProps {
|
|
13
21
|
vpc: ec2.Vpc
|
|
@@ -25,8 +33,7 @@ export class ComputeStack {
|
|
|
25
33
|
const vpc = props.vpc
|
|
26
34
|
const fileSystem = props.fileSystem
|
|
27
35
|
|
|
28
|
-
if (!fileSystem)
|
|
29
|
-
throw new Error('The file system is missing. Please make sure it was created properly.')
|
|
36
|
+
if (!fileSystem) throw new Error('The file system is missing. Please make sure it was created properly.')
|
|
30
37
|
|
|
31
38
|
this.cluster = new ecs.Cluster(scope, 'StacksCluster', {
|
|
32
39
|
clusterName: `${props.slug}-${props.appEnv}-web-server-cluster`,
|
|
@@ -79,11 +86,7 @@ export class ComputeStack {
|
|
|
79
86
|
})
|
|
80
87
|
|
|
81
88
|
// Assuming serviceSecurityGroup and publicLoadBalancerSG are already defined
|
|
82
|
-
serviceSecurityGroup.addIngressRule(
|
|
83
|
-
publicLoadBalancerSG,
|
|
84
|
-
ec2.Port.allTraffic(),
|
|
85
|
-
'Ingress from the public ALB',
|
|
86
|
-
)
|
|
89
|
+
serviceSecurityGroup.addIngressRule(publicLoadBalancerSG, ec2.Port.allTraffic(), 'Ingress from the public ALB')
|
|
87
90
|
|
|
88
91
|
this.lb = new elbv2.ApplicationLoadBalancer(scope, 'ApplicationLoadBalancer', {
|
|
89
92
|
http2Enabled: true,
|
|
@@ -183,8 +186,27 @@ export class ComputeStack {
|
|
|
183
186
|
scaleOutCooldown: Duration.seconds(60),
|
|
184
187
|
})
|
|
185
188
|
|
|
186
|
-
const keysToRemove = [
|
|
187
|
-
|
|
189
|
+
const keysToRemove = [
|
|
190
|
+
'_HANDLER',
|
|
191
|
+
'_X_AMZN_TRACE_ID',
|
|
192
|
+
'AWS_REGION',
|
|
193
|
+
'AWS_EXECUTION_ENV',
|
|
194
|
+
'AWS_LAMBDA_FUNCTION_NAME',
|
|
195
|
+
'AWS_LAMBDA_FUNCTION_MEMORY_SIZE',
|
|
196
|
+
'AWS_LAMBDA_FUNCTION_VERSION',
|
|
197
|
+
'AWS_LAMBDA_INITIALIZATION_TYPE',
|
|
198
|
+
'AWS_LAMBDA_LOG_GROUP_NAME',
|
|
199
|
+
'AWS_LAMBDA_LOG_STREAM_NAME',
|
|
200
|
+
'AWS_ACCESS_KEY',
|
|
201
|
+
'AWS_ACCESS_KEY_ID',
|
|
202
|
+
'AWS_SECRET_ACCESS_KEY',
|
|
203
|
+
'AWS_SESSION_TOKEN',
|
|
204
|
+
'AWS_LAMBDA_RUNTIME_API',
|
|
205
|
+
'LAMBDA_TASK_ROOT',
|
|
206
|
+
'LAMBDA_RUNTIME_DIR',
|
|
207
|
+
'_',
|
|
208
|
+
]
|
|
209
|
+
keysToRemove.forEach((key) => delete env[key as EnvKey])
|
|
188
210
|
|
|
189
211
|
const secrets = new secretsmanager.Secret(scope, 'StacksSecrets', {
|
|
190
212
|
secretName: `${props.slug}-${props.appEnv}-secrets`,
|
|
@@ -195,7 +217,7 @@ export class ComputeStack {
|
|
|
195
217
|
},
|
|
196
218
|
})
|
|
197
219
|
|
|
198
|
-
secrets.grantRead(service.taskDefinition.executionRole
|
|
220
|
+
secrets.grantRead(service.taskDefinition.executionRole)
|
|
199
221
|
container.addEnvironment('SECRETS_ARN', secrets.secretArn)
|
|
200
222
|
|
|
201
223
|
const apiPrefix = 'api'
|
package/src/cloud/dashboard.ts
CHANGED
package/src/cloud/database.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { aws_ec2 as ec2 } from 'aws-cdk-lib'
|
|
2
|
+
import { RemovalPolicy, aws_dynamodb as dynamodb } from 'aws-cdk-lib'
|
|
3
|
+
import type { Construct } from 'constructs'
|
|
4
|
+
import type { NestedCloudProps } from '../types'
|
|
5
|
+
|
|
6
|
+
export interface DatabaseStackProps extends NestedCloudProps {
|
|
7
|
+
vpc: ec2.Vpc
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class DatabaseStack {
|
|
11
|
+
database: dynamodb.Table
|
|
12
|
+
|
|
13
|
+
constructor(scope: Construct, props: DatabaseStackProps) {
|
|
14
|
+
this.database = new dynamodb.Table(scope, 'Database', {
|
|
15
|
+
tableName: `${props.slug}-${props.appEnv}-database`,
|
|
16
|
+
partitionKey: {
|
|
17
|
+
// wip
|
|
18
|
+
name: 'id',
|
|
19
|
+
type: dynamodb.AttributeType.STRING,
|
|
20
|
+
},
|
|
21
|
+
sortKey: {
|
|
22
|
+
// wip
|
|
23
|
+
name: 'sort',
|
|
24
|
+
type: dynamodb.AttributeType.STRING,
|
|
25
|
+
},
|
|
26
|
+
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
|
|
27
|
+
readCapacity: 5,
|
|
28
|
+
writeCapacity: 5,
|
|
29
|
+
pointInTimeRecovery: true,
|
|
30
|
+
removalPolicy: RemovalPolicy.DESTROY,
|
|
31
|
+
encryption: dynamodb.TableEncryption.AWS_MANAGED,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/cloud/deployment.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/* eslint-disable no-new */
|
|
2
|
-
import type { aws_cloudfront as cloudfront, aws_s3 as s3 } from 'aws-cdk-lib'
|
|
3
|
-
import { AssetHashType, aws_s3_deployment as s3deploy } from 'aws-cdk-lib'
|
|
4
1
|
import { config } from '@stacksjs/config'
|
|
5
2
|
import { websiteSourceHash } from '@stacksjs/utils'
|
|
3
|
+
import type { aws_cloudfront as cloudfront, aws_s3 as s3 } from 'aws-cdk-lib'
|
|
4
|
+
import { AssetHashType, aws_s3_deployment as s3deploy } from 'aws-cdk-lib'
|
|
6
5
|
import type { Construct } from 'constructs'
|
|
7
6
|
import type { NestedCloudProps } from '../types'
|
|
8
7
|
|
|
@@ -24,10 +23,12 @@ export class DeploymentStack {
|
|
|
24
23
|
this.websiteSource = config.app.docMode === true ? this.docsSource : '../views/dist/'
|
|
25
24
|
|
|
26
25
|
new s3deploy.BucketDeployment(scope, 'Website', {
|
|
27
|
-
sources: [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
sources: [
|
|
27
|
+
s3deploy.Source.asset(this.websiteSource, {
|
|
28
|
+
assetHash: websiteSourceHash(),
|
|
29
|
+
assetHashType: AssetHashType.CUSTOM,
|
|
30
|
+
}),
|
|
31
|
+
],
|
|
31
32
|
destinationBucket: props.publicBucket,
|
|
32
33
|
distribution: props.cdn,
|
|
33
34
|
distributionPaths: ['/*'],
|
package/src/cloud/dns.ts
CHANGED
package/src/cloud/docs.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
/* eslint-disable no-new */
|
|
2
|
-
import type { CfnResource } from 'aws-cdk-lib'
|
|
3
|
-
import { AssetHashType, CfnOutput as Output, RemovalPolicy, aws_lambda as lambda } from 'aws-cdk-lib'
|
|
4
|
-
import type { Construct } from 'constructs'
|
|
5
1
|
import { config } from '@stacksjs/config'
|
|
6
2
|
import { path as p } from '@stacksjs/path'
|
|
7
3
|
import { storage } from '@stacksjs/storage'
|
|
8
4
|
import { originRequestFunctionHash } from '@stacksjs/utils'
|
|
5
|
+
import type { CfnResource } from 'aws-cdk-lib'
|
|
6
|
+
import { AssetHashType, CfnOutput as Output, RemovalPolicy, aws_lambda as lambda } from 'aws-cdk-lib'
|
|
7
|
+
import type { Construct } from 'constructs'
|
|
9
8
|
import type { NestedCloudProps } from '../types'
|
|
10
9
|
|
|
11
10
|
export interface DocsStackProps extends NestedCloudProps {
|
package/src/cloud/email.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
/* eslint-disable no-new */
|
|
2
|
-
import { Duration, RemovalPolicy, Stack, Tags, aws_iam as iam, aws_lambda as lambda, aws_route53 as route53, aws_s3 as s3, aws_s3_notifications as s3n, aws_ses as ses } from 'aws-cdk-lib'
|
|
3
1
|
import { config } from '@stacksjs/config'
|
|
2
|
+
import {
|
|
3
|
+
Duration,
|
|
4
|
+
RemovalPolicy,
|
|
5
|
+
Stack,
|
|
6
|
+
Tags,
|
|
7
|
+
aws_iam as iam,
|
|
8
|
+
aws_lambda as lambda,
|
|
9
|
+
aws_route53 as route53,
|
|
10
|
+
aws_s3 as s3,
|
|
11
|
+
aws_s3_notifications as s3n,
|
|
12
|
+
aws_ses as ses,
|
|
13
|
+
} from 'aws-cdk-lib'
|
|
4
14
|
import type { Construct } from 'constructs'
|
|
5
15
|
import type { NestedCloudProps } from '../types'
|
|
6
16
|
|
|
@@ -68,18 +78,16 @@ export class EmailStack {
|
|
|
68
78
|
sid: 'AllowSESPuts',
|
|
69
79
|
effect: iam.Effect.ALLOW,
|
|
70
80
|
principals: [sesPrincipal],
|
|
71
|
-
actions: [
|
|
72
|
-
|
|
73
|
-
],
|
|
74
|
-
resources: [
|
|
75
|
-
`${this.emailBucket.bucketArn}/*`,
|
|
76
|
-
],
|
|
81
|
+
actions: ['s3:PutObject'],
|
|
82
|
+
resources: [`${this.emailBucket.bucketArn}/*`],
|
|
77
83
|
conditions: {
|
|
78
84
|
StringEquals: {
|
|
79
85
|
'aws:SourceAccount': Stack.of(scope).account,
|
|
80
86
|
},
|
|
81
87
|
ArnLike: {
|
|
82
|
-
'aws:SourceArn': `arn:aws:ses:${Stack.of(scope).region}:${
|
|
88
|
+
'aws:SourceArn': `arn:aws:ses:${Stack.of(scope).region}:${
|
|
89
|
+
Stack.of(scope).account
|
|
90
|
+
}:receipt-rule-set/${ruleSetName}:receipt-rule/${receiptRuleName}`,
|
|
83
91
|
},
|
|
84
92
|
},
|
|
85
93
|
}),
|
|
@@ -130,10 +138,7 @@ export class EmailStack {
|
|
|
130
138
|
's3:PutObjectAcl',
|
|
131
139
|
's3:PutObjectVersionAcl',
|
|
132
140
|
],
|
|
133
|
-
resources: [
|
|
134
|
-
this.emailBucket.bucketArn,
|
|
135
|
-
`${this.emailBucket.bucketArn}/*`,
|
|
136
|
-
],
|
|
141
|
+
resources: [this.emailBucket.bucketArn, `${this.emailBucket.bucketArn}/*`],
|
|
137
142
|
})
|
|
138
143
|
|
|
139
144
|
const policy = new iam.Policy(scope, 'EmailAccessPolicy', {
|
|
@@ -194,10 +199,12 @@ export class EmailStack {
|
|
|
194
199
|
new route53.MxRecord(scope, 'MxRecord', {
|
|
195
200
|
zone: props.zone,
|
|
196
201
|
recordName: 'mail',
|
|
197
|
-
values: [
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
202
|
+
values: [
|
|
203
|
+
{
|
|
204
|
+
priority: 10,
|
|
205
|
+
hostName: 'feedback-smtp.us-east-1.amazonses.com',
|
|
206
|
+
},
|
|
207
|
+
],
|
|
201
208
|
})
|
|
202
209
|
|
|
203
210
|
new route53.TxtRecord(scope, 'TxtSpfRecord', {
|
|
@@ -215,9 +222,7 @@ export class EmailStack {
|
|
|
215
222
|
const lambdaEmailOutboundRole = new iam.Role(scope, 'LambdaEmailOutboundRole', {
|
|
216
223
|
roleName: `${props.slug}-${props.appEnv}-email-outbound`,
|
|
217
224
|
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
|
|
218
|
-
managedPolicies: [
|
|
219
|
-
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole'),
|
|
220
|
-
],
|
|
225
|
+
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole')],
|
|
221
226
|
})
|
|
222
227
|
|
|
223
228
|
const lambdaEmailOutbound = new lambda.Function(scope, 'LambdaEmailOutbound', {
|
|
@@ -247,9 +252,7 @@ export class EmailStack {
|
|
|
247
252
|
const lambdaEmailInboundRole = new iam.Role(scope, 'LambdaEmailInboundRole', {
|
|
248
253
|
roleName: `${props.slug}-${props.appEnv}-email-inbound`,
|
|
249
254
|
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
|
|
250
|
-
managedPolicies: [
|
|
251
|
-
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole'),
|
|
252
|
-
],
|
|
255
|
+
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole')],
|
|
253
256
|
})
|
|
254
257
|
|
|
255
258
|
const lambdaEmailInbound = new lambda.Function(scope, 'LambdaEmailInbound', {
|
|
@@ -275,10 +278,7 @@ export class EmailStack {
|
|
|
275
278
|
const inboundS3PolicyStatement = new iam.PolicyStatement({
|
|
276
279
|
effect: iam.Effect.ALLOW,
|
|
277
280
|
actions: ['s3:*'],
|
|
278
|
-
resources: [
|
|
279
|
-
this.emailBucket.bucketArn,
|
|
280
|
-
`${this.emailBucket.bucketArn}/*`,
|
|
281
|
-
],
|
|
281
|
+
resources: [this.emailBucket.bucketArn, `${this.emailBucket.bucketArn}/*`],
|
|
282
282
|
})
|
|
283
283
|
|
|
284
284
|
lambdaEmailInboundRole.addToPolicy(inboundS3PolicyStatement)
|
|
@@ -294,15 +294,15 @@ export class EmailStack {
|
|
|
294
294
|
const lambdaEmailConverterRole = new iam.Role(scope, 'LambdaEmailConverterRole', {
|
|
295
295
|
roleName: `${props.slug}-${props.appEnv}-email-converter`,
|
|
296
296
|
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
|
|
297
|
-
managedPolicies: [
|
|
298
|
-
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole'),
|
|
299
|
-
],
|
|
297
|
+
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole')],
|
|
300
298
|
})
|
|
301
299
|
|
|
302
300
|
const lambdaEmailConverter = new lambda.Function(scope, 'LambdaEmailConverter', {
|
|
303
301
|
functionName: `${props.slug}-${props.appEnv}-email-converter`,
|
|
304
302
|
description: 'This Lambda converts raw emails files in to HTML and text.',
|
|
305
|
-
code: lambda.Code.fromInline(
|
|
303
|
+
code: lambda.Code.fromInline(
|
|
304
|
+
'exports.handler = async (event) => {console.log("hello world email converter");return true;};',
|
|
305
|
+
), // this needs to be updated with the real lambda code
|
|
306
306
|
handler: 'index.handler',
|
|
307
307
|
memorySize: 256,
|
|
308
308
|
role: lambdaEmailConverterRole,
|
|
@@ -316,10 +316,7 @@ export class EmailStack {
|
|
|
316
316
|
const converterS3PolicyStatement = new iam.PolicyStatement({
|
|
317
317
|
effect: iam.Effect.ALLOW,
|
|
318
318
|
actions: ['s3:*'],
|
|
319
|
-
resources: [
|
|
320
|
-
this.emailBucket.bucketArn,
|
|
321
|
-
`${this.emailBucket.bucketArn}/*`,
|
|
322
|
-
],
|
|
319
|
+
resources: [this.emailBucket.bucketArn, `${this.emailBucket.bucketArn}/*`],
|
|
323
320
|
})
|
|
324
321
|
|
|
325
322
|
new lambda.CfnPermission(scope, 'S3ConverterPermission', {
|
|
@@ -330,10 +327,30 @@ export class EmailStack {
|
|
|
330
327
|
|
|
331
328
|
lambdaEmailConverterRole.addToPolicy(converterS3PolicyStatement)
|
|
332
329
|
|
|
333
|
-
this.emailBucket.addEventNotification(
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
330
|
+
this.emailBucket.addEventNotification(
|
|
331
|
+
s3.EventType.OBJECT_CREATED_PUT,
|
|
332
|
+
new s3n.LambdaDestination(lambdaEmailInbound),
|
|
333
|
+
{ prefix: 'tmp/email_in/' },
|
|
334
|
+
)
|
|
335
|
+
this.emailBucket.addEventNotification(
|
|
336
|
+
s3.EventType.OBJECT_CREATED_PUT,
|
|
337
|
+
new s3n.LambdaDestination(lambdaEmailOutbound),
|
|
338
|
+
{ prefix: 'tmp/email_out/json/' },
|
|
339
|
+
)
|
|
340
|
+
this.emailBucket.addEventNotification(
|
|
341
|
+
s3.EventType.OBJECT_CREATED_COPY,
|
|
342
|
+
new s3n.LambdaDestination(lambdaEmailConverter),
|
|
343
|
+
{ prefix: 'sent/' },
|
|
344
|
+
)
|
|
345
|
+
this.emailBucket.addEventNotification(
|
|
346
|
+
s3.EventType.OBJECT_CREATED_COPY,
|
|
347
|
+
new s3n.LambdaDestination(lambdaEmailConverter),
|
|
348
|
+
{ prefix: 'inbox/' },
|
|
349
|
+
)
|
|
350
|
+
this.emailBucket.addEventNotification(
|
|
351
|
+
s3.EventType.OBJECT_CREATED_COPY,
|
|
352
|
+
new s3n.LambdaDestination(lambdaEmailConverter),
|
|
353
|
+
{ prefix: 'today/' },
|
|
354
|
+
)
|
|
338
355
|
}
|
|
339
356
|
}
|