@byaga/cdk-patterns 0.11.5 → 0.11.6

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.
Files changed (111) hide show
  1. package/LICENSE.md +20 -20
  2. package/README.md +42 -42
  3. package/eslint.config.mjs +12 -0
  4. package/lib/build/copy-files.d.ts +4 -5
  5. package/lib/build/copy-files.js +26 -21
  6. package/lib/build/generate-hash.d.ts +2 -3
  7. package/lib/build/generate-hash.js +3 -5
  8. package/lib/build/get-files.d.ts +3 -3
  9. package/lib/build/get-files.js +3 -3
  10. package/lib/build/get-source-directory.d.ts +8 -8
  11. package/lib/build/get-source-directory.js +13 -13
  12. package/lib/build/hash-file.js +4 -5
  13. package/lib/build/index.d.ts +2 -0
  14. package/lib/build/index.js +21 -0
  15. package/lib/build/nodejs/build-ecmascript.d.ts +3 -3
  16. package/lib/build/nodejs/build-ecmascript.js +4 -5
  17. package/lib/build/nodejs/build-node-source.d.ts +9 -3
  18. package/lib/build/nodejs/build-node-source.js +10 -11
  19. package/lib/build/nodejs/build-typescript.d.ts +3 -3
  20. package/lib/build/nodejs/build-typescript.js +7 -10
  21. package/lib/build/nodejs/index.d.ts +1 -0
  22. package/lib/build/nodejs/index.js +5 -0
  23. package/lib/build/nodejs/install-node-modules.d.ts +4 -3
  24. package/lib/build/nodejs/install-node-modules.js +6 -6
  25. package/lib/cloud-formation/DeployStack.d.ts +11 -0
  26. package/lib/cloud-formation/DeployStack.js +2 -0
  27. package/lib/cloud-formation/create-stack.d.ts +20 -0
  28. package/lib/cloud-formation/create-stack.js +31 -0
  29. package/lib/cloud-formation/current-stack.d.ts +10 -0
  30. package/lib/cloud-formation/current-stack.js +19 -0
  31. package/lib/{generate-identifier.js → cloud-formation/generate-identifier.js} +7 -8
  32. package/lib/cloud-formation/index.d.ts +5 -0
  33. package/lib/cloud-formation/index.js +14 -0
  34. package/lib/cloud-formation/output.d.ts +2 -0
  35. package/lib/cloud-formation/output.js +12 -0
  36. package/lib/cloud-front/distribution.d.ts +16 -0
  37. package/lib/cloud-front/distribution.js +43 -0
  38. package/lib/cloud-front/index.d.ts +1 -0
  39. package/lib/cloud-front/index.js +5 -0
  40. package/lib/cloud-watch/create-log-group.js +4 -6
  41. package/lib/cloud-watch/index.d.ts +1 -0
  42. package/lib/cloud-watch/index.js +5 -0
  43. package/lib/cloud-watch/set-log-retention.d.ts +2 -0
  44. package/lib/cloud-watch/set-log-retention.js +14 -0
  45. package/lib/index.d.ts +11 -8
  46. package/lib/index.js +13 -29
  47. package/lib/lambda/create-function.d.ts +4 -2
  48. package/lib/lambda/create-function.js +15 -23
  49. package/lib/lambda/create-nodejs-lambda.d.ts +2 -2
  50. package/lib/lambda/create-nodejs-lambda.js +3 -4
  51. package/lib/lambda/index.d.ts +1 -0
  52. package/lib/lambda/index.js +5 -0
  53. package/lib/lambda-layer/apply-honeycomb-to-lambda.d.ts +1 -1
  54. package/lib/lambda-layer/apply-honeycomb-to-lambda.js +4 -5
  55. package/lib/lambda-layer/get-layer.js +4 -6
  56. package/lib/lambda-layer/index.d.ts +2 -0
  57. package/lib/lambda-layer/index.js +7 -0
  58. package/lib/lambda-layer/layer-cache.d.ts +3 -3
  59. package/lib/lambda-layer/layer-cache.js +3 -9
  60. package/lib/load-configuration.d.ts +3 -8
  61. package/lib/load-configuration.js +20 -11
  62. package/lib/recipes/ICorsConfig.d.ts +5 -0
  63. package/lib/recipes/ICorsConfig.js +2 -0
  64. package/lib/recipes/index.d.ts +1 -0
  65. package/lib/recipes/index.js +5 -0
  66. package/lib/recipes/staticWebSite.d.ts +13 -0
  67. package/lib/recipes/staticWebSite.js +54 -0
  68. package/lib/route53/IDomainConfig.d.ts +7 -0
  69. package/lib/route53/IDomainConfig.js +2 -0
  70. package/lib/route53/IHostedZoneConfig.d.ts +5 -0
  71. package/lib/route53/IHostedZoneConfig.js +2 -0
  72. package/lib/route53/apiCertificate.d.ts +13 -0
  73. package/lib/route53/apiCertificate.js +30 -0
  74. package/lib/route53/index.d.ts +3 -0
  75. package/lib/route53/index.js +5 -0
  76. package/lib/s3/bucket.d.ts +8 -0
  77. package/lib/s3/bucket.js +21 -0
  78. package/lib/s3/index.d.ts +1 -0
  79. package/lib/s3/index.js +5 -0
  80. package/lib/ssm/SsmParameter.d.ts +2 -2
  81. package/lib/ssm/StringParameter.d.ts +9 -0
  82. package/lib/ssm/StringParameter.js +15 -0
  83. package/lib/ssm/get-existing-parameter.js +4 -6
  84. package/lib/ssm/grant-read.js +1 -2
  85. package/lib/ssm/index.d.ts +1 -0
  86. package/lib/ssm/index.js +3 -1
  87. package/lib/ssm/parameter-cache.js +2 -3
  88. package/lib/ssm/string-value.js +1 -2
  89. package/lib/tools/index.d.ts +3 -0
  90. package/lib/tools/index.js +10 -0
  91. package/package.json +21 -15
  92. package/tsconfig.json +2 -2
  93. package/.fleet/run.json +0 -11
  94. package/archive/ApiAttachPoint.ts +0 -9
  95. package/archive/ApiCertificate.ts +0 -32
  96. package/archive/CognitoApiGatewayAuthorizer.ts +0 -25
  97. package/archive/DynamoDbTable.ts +0 -40
  98. package/archive/ICorsConfig.ts +0 -5
  99. package/archive/IDomainConfig.ts +0 -8
  100. package/archive/IHostedZoneConfig.ts +0 -5
  101. package/archive/NodeJsLambdaLayer.ts +0 -42
  102. package/archive/Output.ts +0 -11
  103. package/archive/RestApi.ts +0 -180
  104. package/archive/Role.ts +0 -165
  105. package/archive/StaticWebSite.ts +0 -158
  106. package/archive/index.ts +0 -18
  107. package/archive/methods/apply-schema-to-method-options.ts +0 -38
  108. package/archive/methods/attach-function-to-api.ts +0 -69
  109. package/lib/create-stack.d.ts +0 -40
  110. package/lib/create-stack.js +0 -48
  111. /package/lib/{generate-identifier.d.ts → cloud-formation/generate-identifier.d.ts} +0 -0
@@ -1,40 +0,0 @@
1
- import {CfnOutput, RemovalPolicy} from 'aws-cdk-lib';
2
- import {Table, BillingMode, AttributeType} from 'aws-cdk-lib/aws-dynamodb'
3
- import {Effect, Policy, PolicyStatement} from "aws-cdk-lib/aws-iam";
4
- import {DeployStack} from "./DeployStack"
5
-
6
- interface DynamoDbTableConfig {
7
- partitionKey: string,
8
- sortKey?: string
9
- }
10
-
11
- export class DynamoDbTable extends Table {
12
- getPolicy: Policy
13
-
14
- constructor(stack: DeployStack, id: string, props: DynamoDbTableConfig) {
15
- console.log('Creating DynamoDb Table', stack.genName(id, 'data-table'))
16
- super(stack, stack.genId(id, 'data-table'), {
17
- tableName: stack.genName(id, 'data-table'),
18
- partitionKey: {name: props.partitionKey, type: AttributeType.STRING},
19
- sortKey: props.sortKey ? {name: props.sortKey, type: AttributeType.STRING} : undefined,
20
- billingMode: BillingMode.PAY_PER_REQUEST,
21
- removalPolicy: RemovalPolicy.DESTROY
22
- });
23
- stack.set('dynamo', id, this)
24
-
25
- new CfnOutput(stack, stack.genId(id, 'table'), {
26
- value: this.tableName,
27
- exportName: stack.genName(id, 'table')
28
- })
29
-
30
- this.getPolicy = new Policy(stack, stack.genId(id, 'get-policy'), {
31
- statements: [
32
- new PolicyStatement({
33
- actions: ['dynamodb:GetItem'],
34
- effect: Effect.ALLOW,
35
- resources: [this.tableArn]
36
- })
37
- ]
38
- })
39
- }
40
- }
@@ -1,5 +0,0 @@
1
- export interface ICorsConfig {
2
- maxAge?: number
3
- exposeHeaders?: string[],
4
- allowOrigin?: string|string[]
5
- }
@@ -1,8 +0,0 @@
1
- import IHostedZoneConfig from "./IHostedZoneConfig";
2
-
3
- export interface IDomainConfig {
4
- domainName: string,
5
- subdomain?: string,
6
- hostedZone: IHostedZoneConfig
7
- }
8
- export default IDomainConfig
@@ -1,5 +0,0 @@
1
- export interface IHostedZoneConfig {
2
- name: string,
3
- id: string
4
- }
5
- export default IHostedZoneConfig
@@ -1,42 +0,0 @@
1
- import {Code, LayerVersion, Runtime} from "aws-cdk-lib/aws-lambda";
2
- import {DeployStack} from "./DeployStack";
3
- import {LayerVersionOptions} from "aws-cdk-lib/aws-lambda/lib/layers";
4
- import {Architecture} from "aws-cdk-lib/aws-lambda/lib/architecture";
5
- import {buildNodeSource} from "./methods/build-node-source";
6
- import duration from "./methods/duration";
7
-
8
- /**
9
- * Interface for the properties of the NodeJsLambdaLayer class.
10
- */
11
- interface NodeJsLambdaLayerProps extends LayerVersionOptions {
12
- readonly compatibleRuntimes?: Runtime[];
13
- readonly compatibleArchitectures?: Architecture[];
14
- }
15
-
16
- /**
17
- * Class representing a Node.js AWS Lambda layer.
18
- * Extends the LayerVersion class from the AWS CDK library.
19
- */
20
- export class NodeJsLambdaLayer extends LayerVersion {
21
- /**
22
- * Constructs a new NodeJsLambdaLayer instance.
23
- * @param {DeployStack} stack - The deployment stack.
24
- * @param {string} id - The ID of the layer.
25
- * @param {NodeJsLambdaLayerProps} props - The properties of the layer.
26
- */
27
- constructor(stack: DeployStack, id: string, props: NodeJsLambdaLayerProps = {}) {
28
- console.log("Building Lambda Layer", id);
29
- const done = duration()
30
- const buildDir = buildNodeSource('lambda-layer', id, {subdirectory:'nodejs'})
31
- console.log('Build Duration (ms)', done())
32
-
33
- super(stack, stack.genId(id), {
34
- compatibleRuntimes: [Runtime.NODEJS_20_X],
35
- ...props,
36
- layerVersionName: stack.genName(id),
37
- code: Code.fromAsset(buildDir),
38
-
39
- });
40
- stack.set('lambda-layer', id, this)
41
- }
42
- }
package/archive/Output.ts DELETED
@@ -1,11 +0,0 @@
1
- import {CfnOutput} from 'aws-cdk-lib/core';
2
- import {DeployStack} from './DeployStack';
3
-
4
- export class Output extends CfnOutput {
5
- constructor(stack: DeployStack, name: string, value: string) {
6
- super(stack, stack.genId(name, 'output'), {
7
- value,
8
- exportName: stack.genName(name)
9
- })
10
- }
11
- }
@@ -1,180 +0,0 @@
1
- import {
2
- BasePathMapping,
3
- ContentHandling,
4
- DomainName,
5
- EndpointType,
6
- IDomainName,
7
- IResource,
8
- MockIntegration,
9
- RestApi as RestApiBase
10
- } from "aws-cdk-lib/aws-apigateway";
11
- import {DeployStack} from "./DeployStack"
12
- import {ICorsConfig} from "./ICorsConfig";
13
- import {Duration, Size} from "aws-cdk-lib";
14
- import {Effect, Policy, PolicyStatement, Role} from "aws-cdk-lib/aws-iam";
15
-
16
- interface IRestApiConfig {
17
- cors?: ICorsConfig,
18
- allowCredentials: boolean
19
- }
20
-
21
- interface IBasePathMappingConfig {
22
- domain?: IDomainName,
23
- domainName?: string,
24
- hostedZoneId?: string
25
- }
26
-
27
- interface IResourceNode {
28
- children: { [key: string]: IResourceNode }
29
- node: IResource
30
- }
31
-
32
- const DEFAULT_EXPOSE_HEADERS = ['Date']
33
-
34
- export class RestApi extends RestApiBase {
35
- _id: string
36
- _tree: IResourceNode
37
-
38
-
39
- constructor(stack: DeployStack, id: string, props: IRestApiConfig) {
40
- const {stage} = stack
41
-
42
- console.log('Defining Rest API', stack.genId(id, 'api'))
43
-
44
- const cors: ICorsConfig = props.cors || {}
45
- const allowOrigins: string[] = Array.isArray(cors.allowOrigin) ? cors.allowOrigin : [cors.allowOrigin || '*']
46
- super(stack, stack.genId(id, 'api'), {
47
- restApiName: stack.genName('api'),
48
- deploy: true,
49
- deployOptions: {
50
- stageName: stage,
51
- tracingEnabled: true
52
- },
53
- minCompressionSize: Size.bytes(1000),
54
- endpointConfiguration: {
55
- types: [EndpointType.EDGE]
56
- },
57
- defaultCorsPreflightOptions: {
58
- allowHeaders: ['*'],
59
- allowMethods: ['*'],
60
- allowCredentials: props.allowCredentials,
61
- allowOrigins,
62
- maxAge: Duration.seconds(cors.maxAge || 86400),
63
- exposeHeaders: cors.exposeHeaders || DEFAULT_EXPOSE_HEADERS
64
- }
65
- })
66
- this._id = id
67
-
68
- // APIs MUST have at least one endpoint, so this will give it one
69
- console.log('Adding health endpoint', '/health')
70
- const health = this.root.addResource('health')
71
- health.addMethod("GET", new MockIntegration({
72
- requestTemplates: {
73
- "application/json": "{\"statusCode\": 200}"
74
- },
75
- integrationResponses: [{
76
- statusCode: '200',
77
- contentHandling: ContentHandling.CONVERT_TO_TEXT,
78
- responseTemplates: {
79
- 'application/json': `
80
- ## See http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
81
- ## This template will pass through all parameters including path, querystring, header, stage variables, and context through to the integration endpoint via the body/payload
82
- #set($allParams = $input.params())
83
- {
84
- "body-json" : $input.json('$'),
85
- "params" : {
86
- #foreach($type in $allParams.keySet())
87
- #set($params = $allParams.get($type))
88
- "$type" : {
89
- #foreach($paramName in $params.keySet())
90
- "$paramName" : "$util.escapeJavaScript($params.get($paramName))"
91
- #if($foreach.hasNext),#end
92
- #end
93
- }
94
- #if($foreach.hasNext),#end
95
- #end
96
- },
97
- "stage-variables" : {
98
- #foreach($key in $stageVariables.keySet())
99
- "$key" : "$util.escapeJavaScript($stageVariables.get($key))"
100
- #if($foreach.hasNext),#end
101
- #end
102
- },
103
- "context" : {
104
- "account-id" : "$context.identity.accountId",
105
- "api-id" : "$context.apiId",
106
- "api-key" : "$context.identity.apiKey",
107
- "authorizer-principal-id" : "$context.authorizer.principalId",
108
- "caller" : "$context.identity.caller",
109
- "cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
110
- "cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
111
- "cognito-identity-id" : "$context.identity.cognitoIdentityId",
112
- "cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
113
- "http-method" : "$context.httpMethod",
114
- "stage" : "$context.stage",
115
- "source-ip" : "$context.identity.sourceIp",
116
- "user" : "$context.identity.user",
117
- "user-agent" : "$context.identity.userAgent",
118
- "user-arn" : "$context.identity.userArn",
119
- "request-id" : "$context.requestId",
120
- "resource-id" : "$context.resourceId",
121
- "resource-path" : "$context.resourcePath"
122
- }
123
- }`
124
- }
125
- }]
126
- }), {
127
- methodResponses: [{statusCode: "200"}]
128
- })
129
-
130
- this._tree = {node: this.root, children: {}}
131
- }
132
-
133
- addBasePathMapping(stack: DeployStack, config: IBasePathMappingConfig) {
134
- let domain = config.domain
135
- if (!domain && config.domainName && config.hostedZoneId) {
136
- domain = DomainName.fromDomainNameAttributes(stack, stack.genName('domain-name'), {
137
- domainName: config.domainName,
138
- domainNameAliasHostedZoneId: config.hostedZoneId,
139
- domainNameAliasTarget: this.restApiRootResourceId
140
- })
141
- }
142
- if (!domain) throw new Error('Missing Domain Configuration For Base Path Mapping')
143
-
144
- new BasePathMapping(stack, stack.genId(this._id, 'base-path-mapping'), {
145
- domainName: domain,
146
- stage: this.deploymentStage,
147
- restApi: this,
148
- basePath: this._id
149
- })
150
- }
151
-
152
- addAuthorizedRole(stack: DeployStack, roleArn: string): PolicyStatement {
153
- const policyStatement = new PolicyStatement({
154
- effect: Effect.ALLOW,
155
- actions: ['execute-api:Invoke']
156
- })
157
-
158
- const authRole = Role.fromRoleArn(stack, stack.genId('authenticated-role'), roleArn)
159
- authRole.attachInlinePolicy(new Policy(stack, stack.genId('api-access-policy'), {
160
- statements: [policyStatement]
161
- }))
162
- return policyStatement;
163
- }
164
-
165
- path(uri: string): IResource {
166
- const {node} = uri.split('/')
167
- .filter(path => !!path)
168
- .reduce((resource, path) => {
169
- if (!resource.children[path]) {
170
- resource.children[path] = {
171
- children: {},
172
- node: resource.node.addResource(path)
173
- }
174
- }
175
- return resource.children[path];
176
- }, this._tree);
177
-
178
- return node
179
- }
180
- }
package/archive/Role.ts DELETED
@@ -1,165 +0,0 @@
1
- import {FederatedPrincipal, IPrincipal, Role as CdkRole} from "aws-cdk-lib/aws-iam";
2
- import {Duration} from "aws-cdk-lib";
3
- import {Output} from './Output'
4
- import {DeployStack} from "./DeployStack";
5
- import {IManagedPolicy} from "aws-cdk-lib/aws-iam/lib/managed-policy";
6
- import {PolicyDocument} from "aws-cdk-lib/aws-iam/lib/policy-document";
7
-
8
- interface IRoleProps {
9
- identityPool: string,
10
- amr: string,
11
- /**
12
- * The IAM principal (i.e. `new ServicePrincipal('sns.amazonaws.com')`) which can assume this role.
13
- *
14
- * You can later modify the assume role policy document by accessing it via
15
- * the `assumeRolePolicy` property.
16
- *
17
- * @stability stable
18
- */
19
- assumedBy?: IPrincipal,
20
-
21
- /**
22
- * (deprecated) ID that the role assumer needs to provide when assuming this role.
23
- *
24
- * If the configured and provided external IDs do not match, the
25
- * AssumeRole operation will fail.
26
- *
27
- * @default No external ID required
28
- * @deprecated see {@link externalIds}
29
- */
30
- readonly externalId?: string;
31
- /**
32
- * List of IDs that the role assumer needs to provide one of when assuming this role.
33
- *
34
- * If the configured and provided external IDs do not match, the
35
- * AssumeRole operation will fail.
36
- *
37
- * @default No external ID required
38
- * @stability stable
39
- */
40
- readonly externalIds?: string[];
41
- /**
42
- * A list of managed policies associated with this role.
43
- *
44
- * You can add managed policies later using
45
- * `addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName(policyName))`.
46
- *
47
- * @default - No managed policies.
48
- * @stability stable
49
- */
50
- readonly managedPolicies?: IManagedPolicy[];
51
- /**
52
- * A list of named policies to inline into this role.
53
- *
54
- * These policies will be
55
- * created with the role, whereas those added by ``addToPolicy`` are added
56
- * using a separate CloudFormation resource (allowing a way around circular
57
- * dependencies that could otherwise be introduced).
58
- *
59
- * @default - No policy is inlined in the Role resource.
60
- * @stability stable
61
- */
62
- readonly inlinePolicies?: {
63
- [name: string]: PolicyDocument;
64
- };
65
- /**
66
- * The path associated with this role.
67
- *
68
- * For information about IAM paths, see
69
- * Friendly Names and Paths in IAM User Guide.
70
- *
71
- * @default /
72
- * @stability stable
73
- */
74
- readonly path?: string;
75
- /**
76
- * AWS supports permissions boundaries for IAM entities (users or roles).
77
- *
78
- * A permissions boundary is an advanced feature for using a managed policy
79
- * to set the maximum permissions that an identity-based policy can grant to
80
- * an IAM entity. An entity's permissions boundary allows it to perform only
81
- * the actions that are allowed by both its identity-based policies and its
82
- * permissions boundaries.
83
- *
84
- * @default - No permissions boundary.
85
- * @stability stable
86
- * @link https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html
87
- */
88
- readonly permissionsBoundary?: IManagedPolicy;
89
- /**
90
- * A name for the IAM role.
91
- *
92
- * For valid values, see the RoleName parameter for
93
- * the CreateRole action in the IAM API Reference.
94
- *
95
- * IMPORTANT: If you specify a name, you cannot perform updates that require
96
- * replacement of this resource. You can perform updates that require no or
97
- * some interruption. If you must replace the resource, specify a new name.
98
- *
99
- * If you specify a name, you must specify the CAPABILITY_NAMED_IAM value to
100
- * acknowledge your template's capabilities. For more information, see
101
- * Acknowledging IAM Resources in AWS CloudFormation Templates.
102
- *
103
- * @default - AWS CloudFormation generates a unique physical ID and uses that ID
104
- * for the role name.
105
- * @stability stable
106
- */
107
- readonly roleName?: string;
108
- /**
109
- * The maximum session duration that you want to set for the specified role.
110
- *
111
- * This setting can have a value from 1 hour (3600sec) to 12 (43200sec) hours.
112
- *
113
- * Anyone who assumes the role from the AWS CLI or API can use the
114
- * DurationSeconds API parameter or the duration-seconds CLI parameter to
115
- * request a longer session. The MaxSessionDuration setting determines the
116
- * maximum duration that can be requested using the DurationSeconds
117
- * parameter.
118
- *
119
- * If users don't specify a value for the DurationSeconds parameter, their
120
- * security credentials are valid for one hour by default. This applies when
121
- * you use the AssumeRole* API operations or the assume-role* CLI operations
122
- * but does not apply when you use those operations to create a console URL.
123
- *
124
- * @default Duration.hours(1)
125
- * @stability stable
126
- * @link https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html
127
- */
128
- readonly maxSessionDuration?: Duration;
129
- /**
130
- * A description of the role.
131
- *
132
- * It can be up to 1000 characters long.
133
- *
134
- * @default - No description.
135
- * @stability stable
136
- */
137
- readonly description?: string;
138
- }
139
-
140
- export class Role extends CdkRole {
141
- constructor(stack: DeployStack, id: string, props: IRoleProps) {
142
- console.log('Defining Role', stack.genId(id))
143
- if (!props.assumedBy) {
144
- props.assumedBy = new FederatedPrincipal(
145
- 'cognito-identity.amazonaws.com',
146
- {
147
- StringEquals: {
148
- 'cognito-identity.amazonaws.com:aud': props.identityPool
149
- },
150
- "ForAnyValue:StringLike": {
151
- 'cognito-identity.amazonaws.com:amr': props.amr
152
- }
153
- },
154
- 'sts:AssumeRoleWithWebIdentity'
155
- )
156
- }
157
-
158
- super(stack, stack.genId(id), {
159
- ...props,
160
- roleName: stack.genName(props.roleName || id),
161
- assumedBy: props.assumedBy
162
- })
163
- new Output(stack, `${id}-arn`, this.roleArn)
164
- }
165
- }
@@ -1,158 +0,0 @@
1
- import {RemovalPolicy} from "aws-cdk-lib/core";
2
- import {Output} from './Output'
3
- import {DeployStack} from "./DeployStack";
4
- import {execSync} from "child_process";
5
- import {Bucket} from "aws-cdk-lib/aws-s3"
6
- import {BucketDeployment, Source} from "aws-cdk-lib/aws-s3-deployment"
7
- import ApiCertificate from "./ApiCertificate";
8
- import {
9
- CloudFrontAllowedMethods,
10
- CloudFrontWebDistribution,
11
- OriginAccessIdentity,
12
- OriginProtocolPolicy, SourceConfiguration,
13
- SSLMethod,
14
- ViewerCertificate,
15
- ViewerProtocolPolicy
16
- } from "aws-cdk-lib/aws-cloudfront"
17
- import IDomainConfig from "./IDomainConfig";
18
- import {PolicyStatement} from "aws-cdk-lib/aws-iam";
19
- import {ARecord, RecordTarget} from "aws-cdk-lib/aws-route53";
20
- import {CloudFrontTarget} from "aws-cdk-lib/aws-route53-targets";
21
- import duration from './methods/duration';
22
- import {buildNodeSource} from './methods/build-node-source'
23
- import {Duration} from "aws-cdk-lib";
24
-
25
- /**
26
- * Configuration interface for the StaticWebSite class.
27
- */
28
- export interface StaticWebSiteConfig {
29
- srcDir?: string,
30
- domain: IDomainConfig,
31
- env: NodeJS.ProcessEnv,
32
- proxy?: SourceConfiguration[]
33
- }
34
-
35
- /**
36
- * Logic which will setup a static web site in AWS with an S3 Bucket, CloudFront Distribution, and Route53 A-Name Record.
37
- */
38
- export class StaticWebSite {
39
- /**
40
- * Constructs a new StaticWebSite instance.
41
- * @param {DeployStack} stack - The deployment stack.
42
- * @param {string} id - The ID of the website.
43
- * @param {StaticWebSiteConfig} props - The configuration properties of the website.
44
- */
45
- constructor(stack: DeployStack, id: string, props: StaticWebSiteConfig) {
46
- console.log('Deploying Static Web Site', id)
47
-
48
- const done = duration()
49
- const buildDir = buildNodeSource('web', id)
50
-
51
- console.log('Building UI Source', id)
52
- execSync('npm run export', {
53
- cwd: buildDir,
54
- env: props.env
55
- })
56
-
57
- console.log('Total Build Duration (ms)', done())
58
- const exportDir: string = buildDir + '/out';
59
-
60
- console.log('Creating HTTPS Certificate', id + '-certificate')
61
- const certificate = new ApiCertificate(stack, id + '-certificate', props.domain);
62
- console.log('Deploying Site Content Bucket', stack.genId(id, "content-bucket"))
63
- const s3BucketSource = new Bucket(stack, stack.genId(id, "content-bucket"), {
64
- bucketName: certificate.domain,
65
- websiteIndexDocument: "index.html",
66
- websiteErrorDocument: "error.html",
67
- removalPolicy: RemovalPolicy.DESTROY,
68
- autoDeleteObjects: true,
69
- publicReadAccess: false,
70
- blockPublicAccess: {
71
- blockPublicAcls: true,
72
- blockPublicPolicy: true,
73
- ignorePublicAcls: true,
74
- restrictPublicBuckets: true
75
- }
76
- });
77
- new Output(stack, `${id}-content-bucket`, s3BucketSource.bucketName);
78
-
79
- const cloudFrontPolicy = new PolicyStatement({
80
- actions: ['s3:GetBucket*', 's3:GetObject*', 's3:List*'],
81
- resources: [s3BucketSource.bucketArn, s3BucketSource.bucketArn + '/*'],
82
- })
83
-
84
- new BucketDeployment(stack, stack.genId(id, 'bucket-deployment'), {
85
- sources: [Source.asset(exportDir)],
86
- destinationBucket: s3BucketSource
87
- })
88
- const originAccessIdentity = new OriginAccessIdentity(stack, "WebsiteOAI");
89
- cloudFrontPolicy.addArnPrincipal(originAccessIdentity.cloudFrontOriginAccessIdentityS3CanonicalUserId);
90
- s3BucketSource.grantRead(originAccessIdentity)
91
-
92
- const distro = new CloudFrontWebDistribution(stack, stack.genId(id, 'cloudfront-web-distribution'), {
93
- enabled: true,
94
- originConfigs: [...props.proxy || [], {
95
- s3OriginSource: {
96
- s3BucketSource,
97
- originAccessIdentity
98
- },
99
- behaviors: [{
100
- allowedMethods: CloudFrontAllowedMethods.GET_HEAD_OPTIONS,
101
- isDefaultBehavior: true
102
- }]
103
- }],
104
- viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
105
- viewerCertificate: ViewerCertificate.fromAcmCertificate(certificate, {
106
- aliases: [certificate.domain],
107
- sslMethod: SSLMethod.SNI
108
- })
109
- })
110
- new Output(stack, `${id}-base-url`, "https://" + certificate.domain);
111
-
112
- console.log('Setting Route53 A-Name Record', props.domain.domainName)
113
- new ARecord(stack, stack.genId('alias'), {
114
- zone: certificate.hostedZone,
115
- recordName: certificate.domain,
116
- target: RecordTarget.fromAlias(new CloudFrontTarget(distro))
117
- })
118
- }
119
-
120
- /**
121
- * Defines a proxy for the static website.
122
- * @param {DeployStack} stack - The deployment stack.
123
- * @param {string} domainName - The domain name.
124
- * @param {string} pathPattern - The path pattern.
125
- * @returns {SourceConfiguration} The source configuration for the proxy.
126
- */
127
- static defineProxy(stack: DeployStack, domainName: string, pathPattern: string): SourceConfiguration {
128
- return {
129
- customOriginSource: {
130
- domainName: domainName,
131
- originPath: `/${stack.stage}`,
132
- originProtocolPolicy: OriginProtocolPolicy.HTTPS_ONLY
133
- },
134
- behaviors: [{
135
- pathPattern,
136
- allowedMethods: CloudFrontAllowedMethods.ALL,
137
- maxTtl: Duration.seconds(0),
138
- minTtl: Duration.seconds(0),
139
- defaultTtl: Duration.seconds(0),
140
- compress: false,
141
- forwardedValues: {
142
- queryString: true,
143
- headers: [
144
- "Authorization",
145
- "User-Agent",
146
- "X-Trace-Id",
147
- "X-Span-Id",
148
- "X-Correlation-Id",
149
- 'Referer',
150
- "User-Agent",
151
- "Accept-Language",
152
- 'Content-Type',
153
- 'Content-Length'
154
- ]
155
- }
156
- }]
157
- } }
158
- }
package/archive/index.ts DELETED
@@ -1,18 +0,0 @@
1
- export {ApiCertificate} from "./ApiCertificate";
2
- export {CognitoApiGatewayAuthorizer} from "./CognitoApiGatewayAuthorizer";
3
- export {DeployStack} from "./DeployStack";
4
- export {DynamoDbTable} from "./DynamoDbTable";
5
- export {IHostedZoneConfig} from "./IHostedZoneConfig";
6
- export {IDomainConfig} from "./IDomainConfig";
7
- export {IStackArguments} from "./IStackArguments";
8
- export {NodeJsLambdaLayer} from "./NodeJsLambdaLayer";
9
- export {Output} from "./Output";
10
- export {RestApi} from "./RestApi";
11
- export {Role} from "./Role";
12
- export {SsmParameter} from "./SsmParameter";
13
- export {StaticWebSite} from "./StaticWebSite";
14
-
15
- export {createFunction} from "./create-function";
16
- export {createNodejsLambda} from "./create-nodejs-lambda";
17
- export {attachFunctionToApi} from "./methods/attach-function-to-api";
18
- export {applySchemaToMethodOptions} from "./methods/apply-schema-to-method-options";
@@ -1,38 +0,0 @@
1
- import {DeployStack} from "../DeployStack";
2
- import {
3
- JsonSchema,
4
- MethodOptions,
5
- Model,
6
- RequestValidator,
7
- IResource
8
- } from "aws-cdk-lib/aws-apigateway";
9
-
10
- /**
11
- * Applies a schema to a method.
12
- * @param {DeployStack} stack - The deployment stack.
13
- * @param {string} name - The name of the method.
14
- * @param {JsonSchema} schema - The schema.
15
- * @param {MethodOptions} options - The method options.
16
- * @param {IResource} path - The path.
17
- * @returns {MethodOptions} The method options with the schema applied.
18
- */
19
- export function applySchemaToMethodOptions(stack: DeployStack, name: string, schema: JsonSchema, options: MethodOptions, path: IResource): MethodOptions {
20
- return {
21
- ...options,
22
- requestValidator: new RequestValidator(stack, stack.genId(name, 'validator'), {
23
- restApi: path.api,
24
- requestValidatorName: stack.genName(name, 'validator'),
25
- validateRequestBody: true
26
- }),
27
- requestModels: {
28
- 'application/json': new Model(stack, stack.genId(name, 'model'), {
29
- schema: schema,
30
- contentType: 'application/json',
31
- restApi: path.api,
32
- modelName: stack.genId(name, 'model')
33
- })
34
- }
35
- }
36
- }
37
-
38
- export default applySchemaToMethodOptions;