-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from reapit/feat/service-quotas
feat: service quota construct
- Loading branch information
Showing
29 changed files
with
8,583 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
quotas.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
src | ||
tests | ||
.eslintrc.js | ||
tsconfig.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "@reapit-cdk/service-quotas", | ||
"version": "0.0.0", | ||
"description": "This construct allows you to IaC your service quotas", | ||
"homepage": "https://github.com/reapit/ts-cdk-constructs/blob/main/packages/modules/service-quotas", | ||
"readme": "https://github.com/reapit/ts-cdk-constructs/blob/main/packages/modules/service-quotas/readme.md", | ||
"bugs": { | ||
"url": "https://github.com/reapit/ts-cdk-constructs/issues" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "Josh Balfour", | ||
"email": "jbalfour@reapit.com" | ||
}, | ||
"repository": { | ||
"url": "https://github.com/reapit/ts-cdk-constructs.git" | ||
}, | ||
"scripts": { | ||
"build": "reapit-cdk-tsup --lambda", | ||
"check": "yarn run root:check -p $(pwd)", | ||
"lint": "echo 'skipping'", | ||
"test": "yarn run root:test -- $(pwd)", | ||
"prepack": "yarn build", | ||
"integ": "yarn run root:integ -- $(pwd)", | ||
"jsii:build": "rpt-cdk-jsii", | ||
"jsii:publish": "rpt-cdk-jsii --publish", | ||
"gen-types": "ts-node src/generate-types.ts" | ||
}, | ||
"main": "src/index.ts", | ||
"types": "src/index.ts", | ||
"publishConfig": { | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts" | ||
}, | ||
"peerDependencies": { | ||
"aws-cdk-lib": "^2.96.2", | ||
"constructs": "^10.2.70" | ||
}, | ||
"devDependencies": { | ||
"@aws-sdk/client-service-quotas": "3.414.0", | ||
"@reapit-cdk/custom-resource-wrapper": "workspace:^", | ||
"@reapit-cdk/eslint-config": "workspace:^", | ||
"@reapit-cdk/integration-tests": "workspace:^", | ||
"@reapit-cdk/jsii": "workspace:^", | ||
"@reapit-cdk/tsup": "workspace:^", | ||
"aws-cdk-lib": "^2.96.2", | ||
"aws-lambda": "^1.0.7", | ||
"aws-sdk-client-mock": "^3.0.0", | ||
"constructs": "^10.2.70", | ||
"ts-node": "^10.9.2", | ||
"varname": "^6.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# @reapit-cdk/service-quotas | ||
|
||
|
||
![npm version](https://img.shields.io/npm/v/@reapit-cdk/service-quotas) | ||
![npm downloads](https://img.shields.io/npm/dm/@reapit-cdk/service-quotas) | ||
![coverage: 0%25](https://img.shields.io/badge/coverage-0%25-red) | ||
![Integ Tests: X](https://img.shields.io/badge/Integ%20Tests-X-red) | ||
|
||
This construct allows you to IaC your service quotas | ||
|
||
## Package Installation: | ||
|
||
```sh | ||
yarn add --dev @reapit-cdk/service-quotas | ||
# or | ||
npm install @reapit-cdk/service-quotas --save-dev | ||
``` | ||
|
||
## Usage | ||
```ts | ||
import { Stack, App } from 'aws-cdk-lib' | ||
import { AWSService, AmazonCloudFrontQuota, ServiceQuotas } from '@reapit-cdk/service-quotas' | ||
|
||
const app = new App() | ||
const stack = new Stack(app, 'stack-name') | ||
const quotas = new ServiceQuotas(stack, 'service-quotas', { | ||
// Fail the stack if your requests aren't granted yet | ||
failIfNotGranted: true, | ||
// Make another request if an existing one is denied | ||
rerequestWhenDenied: true, | ||
}) | ||
|
||
quotas.requestQuota( | ||
// region | ||
'us-east-1', | ||
// service (use the AWSService.${Service} helper or specify the e.g. 'cloudfront' string as any) | ||
AWSService.AmazonCloudFront, | ||
// quota (use the ${Service}Quota e.g. AmazonCloudFrontQuota helper or specify the 'LL-' string as any) | ||
AmazonCloudFrontQuota.CacheBehaviorsPerDistribution, | ||
// desired value | ||
100, | ||
) | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Construct } from 'constructs' | ||
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda' | ||
import * as path from 'path' | ||
import { CustomResource, Duration, Lazy } from 'aws-cdk-lib' | ||
import { PolicyStatement } from 'aws-cdk-lib/aws-iam' | ||
import { Provider } from 'aws-cdk-lib/custom-resources' | ||
import { Config, Quota } from './types' | ||
|
||
import { AWSService, ServiceQuotaMap } from './quotas' | ||
|
||
export class ServiceQuotas extends Construct { | ||
private quotas: Quota[] = [] | ||
config: Config | ||
|
||
constructor(scope: Construct, id: string, config: Config) { | ||
super(scope, id) | ||
|
||
this.config = config | ||
|
||
const lambda = new Function(this, 'lambda', { | ||
code: Code.fromAsset(path.join(__dirname, '..', 'dist', 'lambda')), | ||
handler: 'lambda.onEvent', | ||
runtime: Runtime.NODEJS_18_X, | ||
timeout: Duration.minutes(15), | ||
}) | ||
|
||
lambda.addToRolePolicy( | ||
new PolicyStatement({ | ||
actions: [ | ||
'servicequotas:ListRequestedServiceQuotaChangeHistoryByQuota', | ||
'servicequotas:GetServiceQuota', | ||
'servicequotas:RequestServiceQuotaIncrease', | ||
], | ||
resources: ['*'], | ||
}), | ||
) | ||
|
||
const provider = new Provider(this, 'provider', { | ||
onEventHandler: lambda, | ||
}) | ||
|
||
const self = this | ||
|
||
new CustomResource(this, 'custom-resource', { | ||
serviceToken: provider.serviceToken, | ||
properties: { | ||
config: this.config, | ||
quotas: Lazy.any({ | ||
produce() { | ||
return self.quotas | ||
}, | ||
}), | ||
}, | ||
}) | ||
} | ||
|
||
requestQuota<S extends AWSService, Q extends ServiceQuotaMap[S]>( | ||
region: string, | ||
service: S, | ||
quota: Q, | ||
desiredValue: number, | ||
) { | ||
this.quotas.push({ | ||
desiredValue, | ||
quota: quota as string, | ||
region, | ||
service, | ||
}) | ||
} | ||
} |
Oops, something went wrong.