@vyriy/stack 0.6.0 → 0.7.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/README.md +13 -2
- package/cloudfront/index.d.ts +2 -1
- package/cloudfront/index.js +1 -0
- package/package.json +1 -1
- package/s3/index.d.ts +2 -1
- package/s3/index.js +1 -0
- package/ses/index.d.ts +2 -5
- package/ses/index.js +3 -11
- package/ssm/index.d.ts +15 -4
- package/ssm/index.js +52 -1
package/README.md
CHANGED
|
@@ -35,7 +35,6 @@ The `aws-cdk-lib` package is listed because CDK apps and bin entrypoints use CDK
|
|
|
35
35
|
- `route53.createARecord(scope, id, props)` creates a Route 53 A record.
|
|
36
36
|
- `route53.createCloudFrontTarget(distribution)` creates a Route 53 alias target for CloudFront.
|
|
37
37
|
- `acm.createCertificate(scope, id, props)` creates an ACM certificate.
|
|
38
|
-
- `ses.createRawEmailBucket(scope, id, props?)` creates a secure retained S3 bucket for raw SES emails.
|
|
39
38
|
- `ses.createEmailReceiving(scope, id, props)` creates an SES domain identity, receipt rule set, receipt rule, raw email bucket permissions, S3-to-Lambda notification, and optional SSM parameter read access.
|
|
40
39
|
- `deployment.createBucketDeployment(scope, id, props)` deploys files to S3 with a `512` MB default memory limit.
|
|
41
40
|
- `deployment.createHtmlCacheControl()` creates cache-control headers for HTML files that should revalidate before reuse.
|
|
@@ -163,7 +162,7 @@ import { CfnOutput, Stack, type StackProps } from 'aws-cdk-lib';
|
|
|
163
162
|
import type { Construct } from 'constructs';
|
|
164
163
|
|
|
165
164
|
import { stack } from '@vyriy/cdk';
|
|
166
|
-
import { lambda, ses } from '@vyriy/stack';
|
|
165
|
+
import { lambda, s3, ses } from '@vyriy/stack';
|
|
167
166
|
import { path } from '@vyriy/path';
|
|
168
167
|
|
|
169
168
|
stack(
|
|
@@ -183,9 +182,11 @@ stack(
|
|
|
183
182
|
},
|
|
184
183
|
handler: 'index.handler',
|
|
185
184
|
});
|
|
185
|
+
const emailBucket = s3.createBucket(this, 'RawEmailBucket');
|
|
186
186
|
|
|
187
187
|
const emailReceiving = ses.createEmailReceiving(this, 'ConsultingEmail', {
|
|
188
188
|
domainName,
|
|
189
|
+
emailBucket,
|
|
189
190
|
processor,
|
|
190
191
|
rawEmailPrefix: 'incoming/',
|
|
191
192
|
receiptRuleName: 'consulting',
|
|
@@ -482,6 +483,12 @@ Read SSM parameter values and import parameters:
|
|
|
482
483
|
```ts
|
|
483
484
|
import { ssm } from '@vyriy/stack';
|
|
484
485
|
|
|
486
|
+
const manualApiKey = ssm.createManualStringParameter(this, 'ManualApiKey', {
|
|
487
|
+
description: 'API key filled after first deploy',
|
|
488
|
+
initialValue: 'CHANGE_ME',
|
|
489
|
+
parameterName: `/${id}/api/key`,
|
|
490
|
+
});
|
|
491
|
+
|
|
485
492
|
const apiBaseUrl = ssm.valueForStringParameter(this, `/${id}/api/base-url`);
|
|
486
493
|
|
|
487
494
|
const importedApiKey = ssm.fromSecureStringParameterAttributes(this, 'ImportedApiKey', {
|
|
@@ -489,10 +496,14 @@ const importedApiKey = ssm.fromSecureStringParameterAttributes(this, 'ImportedAp
|
|
|
489
496
|
version: 1,
|
|
490
497
|
});
|
|
491
498
|
|
|
499
|
+
manualApiKey.grantRead(apiLambda);
|
|
492
500
|
importedApiKey.grantRead(apiLambda);
|
|
493
501
|
importedApiKey.grantRead(taskDefinition.taskRole);
|
|
494
502
|
```
|
|
495
503
|
|
|
504
|
+
`createManualStringParameter` writes the initial value only when CloudFormation creates the resource. Later stack updates do
|
|
505
|
+
not overwrite a manually edited value, and stack deletion removes the parameter.
|
|
506
|
+
|
|
496
507
|
Pass SSM parameter values into Lambda and Fargate environment variables:
|
|
497
508
|
|
|
498
509
|
```ts
|
package/cloudfront/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
|
-
import { AddBehaviorOptions, Distribution, DistributionProps, Function as CloudFrontFunction, FunctionAssociation, FunctionProps, ViewerProtocolPolicy } from 'aws-cdk-lib/aws-cloudfront';
|
|
2
|
+
import { AddBehaviorOptions, Distribution, DistributionProps, Function as CloudFrontFunction, FunctionAssociation, FunctionProps, ViewerProtocolPolicy, DistributionAttributes } from 'aws-cdk-lib/aws-cloudfront';
|
|
3
3
|
import { HttpOrigin } from 'aws-cdk-lib/aws-cloudfront-origins';
|
|
4
4
|
import { Bucket } from 'aws-cdk-lib/aws-s3';
|
|
5
5
|
export { FunctionEventType, OriginProtocolPolicy, ViewerProtocolPolicy } from 'aws-cdk-lib/aws-cloudfront';
|
|
@@ -12,6 +12,7 @@ export interface CreateIndexRewriteFunctionCodeProps {
|
|
|
12
12
|
}
|
|
13
13
|
export interface CreateFunctionAssociationsProps extends CreateIndexRewriteFunctionCodeProps, Omit<CreateCloudFrontFunctionProps, 'code'> {
|
|
14
14
|
}
|
|
15
|
+
export declare const findDistribution: (scope: Construct, id: string, props: DistributionAttributes) => import("aws-cdk-lib/aws-cloudfront").IDistribution;
|
|
15
16
|
export declare const createDistribution: (scope: Construct, id: string, props: DistributionProps) => Distribution;
|
|
16
17
|
export declare const createCloudFrontFunction: (scope: Construct, id: string, props: CreateCloudFrontFunctionProps) => CloudFrontFunction;
|
|
17
18
|
export declare const createIndexRewriteFunctionCode: ({ rootDomain, wwwDomain }: CreateIndexRewriteFunctionCodeProps) => string;
|
package/cloudfront/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Distribution, Function as CloudFrontFunction, FunctionCode, FunctionEventType, OriginProtocolPolicy, ViewerProtocolPolicy, } from 'aws-cdk-lib/aws-cloudfront';
|
|
2
2
|
import { HttpOrigin, S3BucketOrigin } from 'aws-cdk-lib/aws-cloudfront-origins';
|
|
3
3
|
export { FunctionEventType, OriginProtocolPolicy, ViewerProtocolPolicy } from 'aws-cdk-lib/aws-cloudfront';
|
|
4
|
+
export const findDistribution = (scope, id, props) => Distribution.fromDistributionAttributes(scope, id, props);
|
|
4
5
|
export const createDistribution = (scope, id, props) => new Distribution(scope, id, props);
|
|
5
6
|
export const createCloudFrontFunction = (scope, id, props) => new CloudFrontFunction(scope, id, {
|
|
6
7
|
...props,
|
package/package.json
CHANGED
package/s3/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import { Bucket, BucketProps } from 'aws-cdk-lib/aws-s3';
|
|
3
|
-
export { RedirectProtocol } from 'aws-cdk-lib/aws-s3';
|
|
3
|
+
export { RedirectProtocol, type BucketProps } from 'aws-cdk-lib/aws-s3';
|
|
4
|
+
export declare const findBucket: (scope: Construct, id: string, bucketName: string) => import("aws-cdk-lib/aws-s3").IBucket;
|
|
4
5
|
export declare const createBucket: (scope: Construct, id: string, props?: BucketProps) => Bucket;
|
package/s3/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RemovalPolicy } from 'aws-cdk-lib';
|
|
2
2
|
import { BlockPublicAccess, Bucket, HttpMethods, BucketEncryption } from 'aws-cdk-lib/aws-s3';
|
|
3
3
|
export { RedirectProtocol } from 'aws-cdk-lib/aws-s3';
|
|
4
|
+
export const findBucket = (scope, id, bucketName) => Bucket.fromBucketName(scope, id, bucketName);
|
|
4
5
|
export const createBucket = (scope, id, props = {}) => {
|
|
5
6
|
const bucketProps = {
|
|
6
7
|
removalPolicy: RemovalPolicy.DESTROY,
|
package/ses/index.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
2
|
import { IFunction } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
-
import {
|
|
3
|
+
import { IBucket } from 'aws-cdk-lib/aws-s3';
|
|
4
4
|
import { CfnEmailIdentity, CfnReceiptRule, CfnReceiptRuleSet } from 'aws-cdk-lib/aws-ses';
|
|
5
5
|
export type ReceiptRuleTlsPolicy = 'Optional' | 'Require';
|
|
6
|
-
export type CreateRawEmailBucketProps = BucketProps;
|
|
7
6
|
export type CreateEmailReceivingProps = {
|
|
8
7
|
domainName: string;
|
|
9
|
-
emailBucket
|
|
10
|
-
emailBucketProps?: CreateRawEmailBucketProps;
|
|
8
|
+
emailBucket: IBucket;
|
|
11
9
|
receiptRuleName: string;
|
|
12
10
|
receiptRuleSetName: string;
|
|
13
11
|
recipients: string[];
|
|
@@ -24,5 +22,4 @@ export type CreateEmailReceivingResult = {
|
|
|
24
22
|
receiptRuleSet: CfnReceiptRuleSet;
|
|
25
23
|
};
|
|
26
24
|
export { CfnEmailIdentity, CfnReceiptRule, CfnReceiptRuleSet } from 'aws-cdk-lib/aws-ses';
|
|
27
|
-
export declare const createRawEmailBucket: (scope: Construct, id: string, props?: CreateRawEmailBucketProps) => Bucket;
|
|
28
25
|
export declare const createEmailReceiving: (scope: Construct, id: string, props: CreateEmailReceivingProps) => CreateEmailReceivingResult;
|
package/ses/index.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import { ArnFormat,
|
|
1
|
+
import { ArnFormat, Stack } from 'aws-cdk-lib';
|
|
2
2
|
import { Effect, PolicyStatement, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
|
|
3
3
|
import { LambdaDestination } from 'aws-cdk-lib/aws-s3-notifications';
|
|
4
|
-
import {
|
|
4
|
+
import { EventType } from 'aws-cdk-lib/aws-s3';
|
|
5
5
|
import { CfnEmailIdentity, CfnReceiptRule, CfnReceiptRuleSet } from 'aws-cdk-lib/aws-ses';
|
|
6
6
|
export { CfnEmailIdentity, CfnReceiptRule, CfnReceiptRuleSet } from 'aws-cdk-lib/aws-ses';
|
|
7
|
-
export const createRawEmailBucket = (scope, id, props = {}) => new Bucket(scope, id, {
|
|
8
|
-
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
|
|
9
|
-
encryption: BucketEncryption.S3_MANAGED,
|
|
10
|
-
enforceSSL: true,
|
|
11
|
-
removalPolicy: RemovalPolicy.RETAIN,
|
|
12
|
-
versioned: true,
|
|
13
|
-
...props,
|
|
14
|
-
});
|
|
15
7
|
export const createEmailReceiving = (scope, id, props) => {
|
|
16
|
-
const { domainName, emailBucket
|
|
8
|
+
const { domainName, emailBucket, processor, rawEmailPrefix = 'incoming/', receiptRuleName, receiptRuleSetName, recipients, scanEnabled = true, ssmParameterNames = [], tlsPolicy = 'Require', } = props;
|
|
17
9
|
const stack = Stack.of(scope);
|
|
18
10
|
const emailIdentity = new CfnEmailIdentity(scope, `${id}EmailIdentity`, {
|
|
19
11
|
dkimAttributes: {
|
package/ssm/index.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { Construct } from 'constructs';
|
|
2
|
-
import { SecureStringParameterAttributes, StringParameterAttributes } from 'aws-cdk-lib/aws-ssm';
|
|
2
|
+
import { IStringParameter, ParameterTier, SecureStringParameterAttributes, StringParameterAttributes } from 'aws-cdk-lib/aws-ssm';
|
|
3
|
+
export interface ManualStringParameterProps {
|
|
4
|
+
allowedPattern?: string;
|
|
5
|
+
dataType?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
initialValue?: string;
|
|
8
|
+
parameterName: string;
|
|
9
|
+
simpleName?: boolean;
|
|
10
|
+
tier?: ParameterTier;
|
|
11
|
+
}
|
|
3
12
|
export type { ParameterValueType } from 'aws-cdk-lib/aws-ssm';
|
|
4
|
-
export
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
13
|
+
export { ParameterTier } from 'aws-cdk-lib/aws-ssm';
|
|
14
|
+
export declare const createManualStringParameter: (scope: Construct, id: string, props: ManualStringParameterProps) => IStringParameter;
|
|
15
|
+
export declare const fromStringParameterName: (scope: Construct, id: string, stringParameterName: string) => IStringParameter;
|
|
16
|
+
export declare const fromStringParameterAttributes: (scope: Construct, id: string, attrs: StringParameterAttributes) => IStringParameter;
|
|
17
|
+
export declare const fromSecureStringParameterAttributes: (scope: Construct, id: string, attrs: SecureStringParameterAttributes) => IStringParameter;
|
|
7
18
|
export declare const valueForStringParameter: (scope: Construct, stringParameterName: string) => string;
|
package/ssm/index.js
CHANGED
|
@@ -1,4 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ArnFormat, Stack } from 'aws-cdk-lib';
|
|
2
|
+
import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from 'aws-cdk-lib/custom-resources';
|
|
3
|
+
import { StringParameter, } from 'aws-cdk-lib/aws-ssm';
|
|
4
|
+
export { ParameterTier } from 'aws-cdk-lib/aws-ssm';
|
|
5
|
+
const defaultManualParameterInitialValue = 'CHANGE_ME';
|
|
6
|
+
const parameterArn = (scope, parameterName) => Stack.of(scope).formatArn({
|
|
7
|
+
arnFormat: ArnFormat.SLASH_RESOURCE_NAME,
|
|
8
|
+
service: 'ssm',
|
|
9
|
+
resource: 'parameter',
|
|
10
|
+
resourceName: parameterName.replace(/^\//, ''),
|
|
11
|
+
});
|
|
12
|
+
const definedParameterProps = (props) => ({
|
|
13
|
+
...(props.allowedPattern === undefined ? {} : { AllowedPattern: props.allowedPattern }),
|
|
14
|
+
...(props.dataType === undefined ? {} : { DataType: props.dataType }),
|
|
15
|
+
...(props.description === undefined ? {} : { Description: props.description }),
|
|
16
|
+
...(props.tier === undefined ? {} : { Tier: props.tier }),
|
|
17
|
+
});
|
|
18
|
+
export const createManualStringParameter = (scope, id, props) => {
|
|
19
|
+
const { initialValue = defaultManualParameterInitialValue, parameterName, simpleName } = props;
|
|
20
|
+
const resource = new AwsCustomResource(scope, `${id}Resource`, {
|
|
21
|
+
installLatestAwsSdk: false,
|
|
22
|
+
onCreate: {
|
|
23
|
+
action: 'putParameter',
|
|
24
|
+
parameters: {
|
|
25
|
+
...definedParameterProps(props),
|
|
26
|
+
Name: parameterName,
|
|
27
|
+
Overwrite: false,
|
|
28
|
+
Type: 'String',
|
|
29
|
+
Value: initialValue,
|
|
30
|
+
},
|
|
31
|
+
physicalResourceId: PhysicalResourceId.of(parameterName),
|
|
32
|
+
service: 'SSM',
|
|
33
|
+
},
|
|
34
|
+
onDelete: {
|
|
35
|
+
action: 'deleteParameter',
|
|
36
|
+
ignoreErrorCodesMatching: 'ParameterNotFound',
|
|
37
|
+
parameters: {
|
|
38
|
+
Name: parameterName,
|
|
39
|
+
},
|
|
40
|
+
service: 'SSM',
|
|
41
|
+
},
|
|
42
|
+
policy: AwsCustomResourcePolicy.fromSdkCalls({
|
|
43
|
+
resources: [parameterArn(scope, parameterName)],
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
const parameter = StringParameter.fromStringParameterAttributes(scope, id, {
|
|
47
|
+
parameterName,
|
|
48
|
+
simpleName,
|
|
49
|
+
});
|
|
50
|
+
parameter.node.addDependency(resource);
|
|
51
|
+
return parameter;
|
|
52
|
+
};
|
|
2
53
|
export const fromStringParameterName = (scope, id, stringParameterName) => StringParameter.fromStringParameterName(scope, id, stringParameterName);
|
|
3
54
|
export const fromStringParameterAttributes = (scope, id, attrs) => StringParameter.fromStringParameterAttributes(scope, id, attrs);
|
|
4
55
|
export const fromSecureStringParameterAttributes = (scope, id, attrs) => StringParameter.fromSecureStringParameterAttributes(scope, id, attrs);
|