From 43bf54ea0c2d17a03525c2af7bd5d16b2f8ff533 Mon Sep 17 00:00:00 2001
From: Yohta Kimura <38206553+rajyan@users.noreply.github.com>
Date: Tue, 30 Aug 2022 06:11:32 +0900
Subject: [PATCH] chore: projen setting improvements (#29)
Fixes #
---
.github/workflows/build.yml | 3 -
.gitignore | 8 +-
.npmignore | 8 +-
.projenrc.ts | 41 ++----
API.md | 140 +++++++++++++-------
test/__snapshots__/easy-cerver.test.ts.snap | 20 +--
6 files changed, 127 insertions(+), 93 deletions(-)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e18abcc..b832f6d 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -4,9 +4,6 @@ name: build
on:
pull_request: {}
workflow_dispatch: {}
- push:
- branches:
- - main
jobs:
build:
runs-on: ubuntu-latest
diff --git a/.gitignore b/.gitignore
index 2a2fe86..761fec1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,10 @@ jspm_packages/
*.tgz
.yarn-integrity
.cache
+.idea/
+cdk.out/
+cdk.context.json
+yarn-error.log
!/.projenrc.js
/test-reports/
junit.xml
@@ -51,7 +55,3 @@ junit.xml
.jsii
tsconfig.json
!/API.md
-.idea/
-cdk.out/
-cdk.context.json
-yarn-error.log
diff --git a/.npmignore b/.npmignore
index d3ae4a4..5aa8bb9 100644
--- a/.npmignore
+++ b/.npmignore
@@ -1,4 +1,8 @@
# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".
+.idea/
+cdk.out/
+cdk.context.json
+yarn-error.log
/.projen/
/test-reports/
junit.xml
@@ -21,7 +25,3 @@ dist
tsconfig.tsbuildinfo
/.eslintrc.json
!.jsii
-.idea/
-cdk.out/
-cdk.context.json
-yarn-error.log
diff --git a/.projenrc.ts b/.projenrc.ts
index df1a975..78d5b83 100644
--- a/.projenrc.ts
+++ b/.projenrc.ts
@@ -1,6 +1,7 @@
import { awscdk } from 'projen';
import { UpgradeDependenciesSchedule } from 'projen/lib/javascript';
+const excludes = ['.idea/', 'cdk.out/', 'cdk.context.json', 'yarn-error.log'];
const project = new awscdk.AwsCdkConstructLibrary({
author: 'Yohta Kimura',
authorAddress: 'kitakita7617@gmail.com',
@@ -10,48 +11,34 @@ const project = new awscdk.AwsCdkConstructLibrary({
license: 'MIT',
cdkVersion: '2.37.0',
defaultReleaseBranch: 'main',
-
- devDeps: [
- 'aws-cdk',
- 'ts-node',
- ],
-
keywords: [
'cdk',
'ecs',
'certbot',
'low-cost',
],
+ devDeps: [
+ 'aws-cdk',
+ 'ts-node',
+ ],
+ stability: 'experimental',
- buildWorkflowTriggers: {
- pullRequest: {},
- workflowDispatch: {},
- push: {
- branches: ['main'],
- },
+ python: {
+ distName: 'easy-cerver',
+ module: 'eascy_cerver',
},
+ npmignore: excludes,
+ gitignore: excludes,
+ autoApproveOptions: {
+ allowedUsernames: ['rajyan'],
+ },
depsUpgradeOptions: {
workflowOptions: {
schedule: UpgradeDependenciesSchedule.WEEKLY,
},
},
-
- stability: 'experimental',
-
- autoApproveOptions: {
- allowedUsernames: ['rajyan'],
- },
- python: {
- distName: 'easy-cerver',
- module: 'eascy_cerver',
- },
-
projenrcTs: true,
});
-const excludes = ['.idea/', 'cdk.out/', 'cdk.context.json', 'yarn-error.log'];
-project.npmignore?.exclude(...excludes);
-project.gitignore.exclude(...excludes);
-
project.synth();
\ No newline at end of file
diff --git a/API.md b/API.md
index b837b80..54bd49d 100644
--- a/API.md
+++ b/API.md
@@ -48,6 +48,7 @@ new EasyCerver(scope: Construct, id: string, props: EasyCerverProps)
| exportValue
| Create a CloudFormation Export for a value. |
| formatArn
| Creates an ARN from components. |
| getLogicalId
| Allocates a stack-unique CloudFormation-compatible logical identity for a specific resource. |
+| regionalFact
| Look up a fact value for the given fact for the region of this stack. |
| renameLogicalId
| Rename a generated logical identities. |
| reportMissingContextKey
| Indicate that a context key was expected. |
| resolve
| Resolve a tokenized value in the context of the current stack. |
@@ -195,7 +196,7 @@ into the generated ARN at the location that component corresponds to.
The ARN will be formatted as follows:
- arn:{partition}:{service}:{region}:{account}:{resource}{sep}}{resource-name}
+ arn:{partition}:{service}:{region}:{account}:{resource}{sep}{resource-name}
The required ARN pieces that are omitted will be taken from the stack that
the 'scope' is attached to. If all ARN pieces are supplied, the supplied scope
@@ -231,6 +232,42 @@ The CloudFormation element for which a logical identity is needed.
---
+##### `regionalFact`
+
+```typescript
+public regionalFact(factName: string, defaultValue?: string): string
+```
+
+Look up a fact value for the given fact for the region of this stack.
+
+Will return a definite value only if the region of the current stack is resolved.
+If not, a lookup map will be added to the stack and the lookup will be done at
+CDK deployment time.
+
+What regions will be included in the lookup map is controlled by the
+`@aws-cdk/core:target-partitions` context value: it must be set to a list
+of partitions, and only regions from the given partitions will be included.
+If no such context key is set, all regions will be included.
+
+This function is intended to be used by construct library authors. Application
+builders can rely on the abstractions offered by construct libraries and do
+not have to worry about regional facts.
+
+If `defaultValue` is not given, it is an error if the fact is unknown for
+the given region.
+
+###### `factName`Required
+
+- *Type:* string
+
+---
+
+###### `defaultValue`Optional
+
+- *Type:* string
+
+---
+
##### `renameLogicalId`
```typescript
@@ -410,11 +447,10 @@ The construct to start the search from.
| account
| string
| The AWS account into which this stack will be deployed. |
| artifactId
| string
| The ID of the cloud assembly artifact for this stack. |
| availabilityZones
| string[]
| Returns the list of AZs that are available in the AWS environment (account/region) associated with this stack. |
+| bundlingRequired
| boolean
| Indicates whether the stack requires bundling or not. |
| dependencies
| aws-cdk-lib.Stack[]
| Return the stacks this stack depends on. |
| environment
| string
| The environment coordinates in which this stack is deployed. |
| nested
| boolean
| Indicates if this is a nested stack, in which case `parentStack` will include a reference to it's parent. |
-| nestedStackParent
| aws-cdk-lib.Stack
| If this is a nested stack, returns it's parent stack. |
-| nestedStackResource
| aws-cdk-lib.CfnResource
| If this is a nested stack, this represents its `AWS::CloudFormation::Stack` resource. |
| notificationArns
| string[]
| Returns the list of notification Amazon Resource Names (ARNs) for the current stack. |
| partition
| string
| The partition in which this stack is defined. |
| region
| string
| The AWS region into which this stack will be deployed (e.g. `us-west-2`). |
@@ -424,8 +460,10 @@ The construct to start the search from.
| tags
| aws-cdk-lib.TagManager
| Tags to be applied to the stack. |
| templateFile
| string
| The name of the CloudFormation template file emitted to the output directory during synthesis. |
| templateOptions
| aws-cdk-lib.ITemplateOptions
| Options for CloudFormation template (like version, transform, description). |
-| terminationProtection
| boolean
| Whether termination protection is enabled for this stack. |
| urlSuffix
| string
| The Amazon domain suffix for the region in which this stack is defined. |
+| nestedStackParent
| aws-cdk-lib.Stack
| If this is a nested stack, returns it's parent stack. |
+| nestedStackResource
| aws-cdk-lib.CfnResource
| If this is a nested stack, this represents its `AWS::CloudFormation::Stack` resource. |
+| terminationProtection
| boolean
| Whether termination protection is enabled for this stack. |
---
@@ -454,9 +492,9 @@ The AWS account into which this stack will be deployed.
This value is resolved according to the following rules:
1. The value provided to `env.account` when the stack is defined. This can
- either be a concerete account (e.g. `585695031111`) or the
- `Aws.accountId` token.
-3. `Aws.accountId`, which represents the CloudFormation intrinsic reference
+ either be a concrete account (e.g. `585695031111`) or the
+ `Aws.ACCOUNT_ID` token.
+3. `Aws.ACCOUNT_ID`, which represents the CloudFormation intrinsic reference
`{ "Ref": "AWS::AccountId" }` encoded as a string token.
Preferably, you should use the return value as an opaque string and not
@@ -505,6 +543,18 @@ To specify a different strategy for selecting availability zones override this m
---
+##### `bundlingRequired`Required
+
+```typescript
+public readonly bundlingRequired: boolean;
+```
+
+- *Type:* boolean
+
+Indicates whether the stack requires bundling or not.
+
+---
+
##### `dependencies`Required
```typescript
@@ -535,7 +585,7 @@ You can use this value to determine if two stacks are targeting the same
environment.
If either `stack.account` or `stack.region` are not concrete values (e.g.
-`Aws.account` or `Aws.region`) the special strings `unknown-account` and/or
+`Aws.ACCOUNT_ID` or `Aws.REGION`) the special strings `unknown-account` and/or
`unknown-region` will be used respectively to indicate this stack is
region/account-agnostic.
@@ -553,32 +603,6 @@ Indicates if this is a nested stack, in which case `parentStack` will include a
---
-##### `nestedStackParent`Optional
-
-```typescript
-public readonly nestedStackParent: Stack;
-```
-
-- *Type:* aws-cdk-lib.Stack
-
-If this is a nested stack, returns it's parent stack.
-
----
-
-##### `nestedStackResource`Optional
-
-```typescript
-public readonly nestedStackResource: CfnResource;
-```
-
-- *Type:* aws-cdk-lib.CfnResource
-
-If this is a nested stack, this represents its `AWS::CloudFormation::Stack` resource.
-
-`undefined` for top-level (non-nested) stacks.
-
----
-
##### `notificationArns`Required
```typescript
@@ -616,9 +640,9 @@ The AWS region into which this stack will be deployed (e.g. `us-west-2`).
This value is resolved according to the following rules:
1. The value provided to `env.region` when the stack is defined. This can
- either be a concerete region (e.g. `us-west-2`) or the `Aws.region`
+ either be a concerete region (e.g. `us-west-2`) or the `Aws.REGION`
token.
-3. `Aws.region`, which is represents the CloudFormation intrinsic reference
+3. `Aws.REGION`, which is represents the CloudFormation intrinsic reference
`{ "Ref": "AWS::Region" }` encoded as a string token.
Preferably, you should use the return value as an opaque string and not
@@ -669,7 +693,7 @@ name. Stacks that are defined deeper within the tree will use a hashed naming
scheme based on the construct path to ensure uniqueness.
If you wish to obtain the deploy-time AWS::StackName intrinsic,
-you can use `Aws.stackName` directly.
+you can use `Aws.STACK_NAME` directly.
---
@@ -723,27 +747,53 @@ Options for CloudFormation template (like version, transform, description).
---
-##### `terminationProtection`Optional
+##### `urlSuffix`Required
```typescript
-public readonly terminationProtection: boolean;
+public readonly urlSuffix: string;
```
-- *Type:* boolean
+- *Type:* string
-Whether termination protection is enabled for this stack.
+The Amazon domain suffix for the region in which this stack is defined.
---
-##### `urlSuffix`Required
+##### `nestedStackParent`Optional
```typescript
-public readonly urlSuffix: string;
+public readonly nestedStackParent: Stack;
```
-- *Type:* string
+- *Type:* aws-cdk-lib.Stack
-The Amazon domain suffix for the region in which this stack is defined.
+If this is a nested stack, returns it's parent stack.
+
+---
+
+##### `nestedStackResource`Optional
+
+```typescript
+public readonly nestedStackResource: CfnResource;
+```
+
+- *Type:* aws-cdk-lib.CfnResource
+
+If this is a nested stack, this represents its `AWS::CloudFormation::Stack` resource.
+
+`undefined` for top-level (non-nested) stacks.
+
+---
+
+##### `terminationProtection`Optional
+
+```typescript
+public readonly terminationProtection: boolean;
+```
+
+- *Type:* boolean
+
+Whether termination protection is enabled for this stack.
---
diff --git a/test/__snapshots__/easy-cerver.test.ts.snap b/test/__snapshots__/easy-cerver.test.ts.snap
index 61aa7a3..9fa9dbe 100644
--- a/test/__snapshots__/easy-cerver.test.ts.snap
+++ b/test/__snapshots__/easy-cerver.test.ts.snap
@@ -107,8 +107,8 @@ Object {
},
"Volumes": Array [
Object {
- "EfsVolumeConfiguration": Object {
- "FileSystemId": Object {
+ "EFSVolumeConfiguration": Object {
+ "FilesystemId": Object {
"Ref": "FileSystem8A8E25C0",
},
},
@@ -284,13 +284,13 @@ autoscaling = boto3.client('autoscaling')
def lambda_handler(event, context):
- print(json.dumps(event))
+ print(json.dumps(dict(event, ResponseURL='...')))
cluster = os.environ['CLUSTER']
snsTopicArn = event['Records'][0]['Sns']['TopicArn']
lifecycle_event = json.loads(event['Records'][0]['Sns']['Message'])
instance_id = lifecycle_event.get('EC2InstanceId')
if not instance_id:
- print('Got event without EC2InstanceId: %s', json.dumps(event))
+ print('Got event without EC2InstanceId: %s', json.dumps(dict(event, ResponseURL='...')))
return
instance_arn = container_instance_arn(cluster, instance_id)
@@ -300,7 +300,7 @@ def lambda_handler(event, context):
return
task_arns = container_instance_task_arns(cluster, instance_arn)
-
+
if task_arns:
print('Instance ARN %s has task ARNs %s' % (instance_arn, ', '.join(task_arns)))
@@ -349,11 +349,11 @@ def has_tasks(cluster, instance_arn, task_arns):
if tasks:
# Consider any non-stopped tasks as running
task_count = sum(task['lastStatus'] != 'STOPPED' for task in tasks) + instance['pendingTasksCount']
-
+
if not task_count:
# Fallback to instance task counts if detailed task information is unavailable
task_count = instance['runningTasksCount'] + instance['pendingTasksCount']
-
+
print('Instance %s has %s tasks' % (instance_arn, task_count))
return task_count > 0
@@ -383,7 +383,7 @@ def pick(dct, *keys):
"Arn",
],
},
- "Runtime": "python3.6",
+ "Runtime": "python3.9",
"Tags": Array [
Object {
"Key": "Name",
@@ -1147,8 +1147,8 @@ docker run --net=host amazon/aws-cli:latest ec2 associate-address --region dummy
},
"Volumes": Array [
Object {
- "EfsVolumeConfiguration": Object {
- "FileSystemId": Object {
+ "EFSVolumeConfiguration": Object {
+ "FilesystemId": Object {
"Ref": "FileSystem8A8E25C0",
},
},