Skip to content

Commit

Permalink
Merge pull request #2 from reapit/feat/userpool-domain-crw-docs
Browse files Browse the repository at this point in the history
add docs
  • Loading branch information
joshbalfour committed Sep 21, 2023
2 parents 1fa564f + 87fa71f commit 77528e8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/custom-resource-wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"devDependencies": {
"@reapit-cdk/eslint": "workspace:^",
"@reapit-cdk/tsup": "workspace:^",
"@reapit-cdk/version-package": "workspace:^",
"@types/aws-lambda": "^8.10.121",
"aws-lambda": "1.0.7"
Expand Down
39 changes: 39 additions & 0 deletions packages/custom-resource-wrapper/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# @reapit-cdk/custom-resource-wrapper

This module helps write custom resource handlers. It's designed to work with the [Custom Resource Provider Framework](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.CustomResource.html).

It accepts an object which contains event handlers for `onCreate`, and optionally, `onUpdate`, and `onDelete`.
Anything returned from `onCreate` and `onUpdate` is returned as data attributes on the resulting custom resource.

## npm Package Installation:
```sh
yarn add @reapit-cdk/custom-resource-wrapper
# or
npm install @reapit-cdk/custom-resource-wrapper
```

## Usage
```ts
import { customResourceWrapper } from '@reapit-cdk/custom-resource-wrapper'

export const onEvent = customResourceWrapper({
onCreate: async ({ aProperty }) => {
const { aDataAttribute } = await createThing(aProperty)
return {
aDataAttribute,
}
},
onUpdate: async ({ aProperty }, oldProps) => {
if (aProperty !== oldProps.aProperty) {
await deleteThing(oldProps.aProperty)
const { aDataAttribute } = await createThing(aProperty)
return {
aDataAttribute,
}
}
},
onDelete: async ({ aProperty }) => {
await deleteThing(aProperty)
},
})
```
26 changes: 26 additions & 0 deletions packages/userpool-domain/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# @reapit-cdk/userpool-domain

This construct returns the given Cognito UserPool's UserPoolDomain, or creates one.
This resolves an issue with [AWS::Cognito::UserPoolDomain](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpooldomain.html), since that will fail if one already exists.

## npm Package Installation:
```sh
yarn add --dev @reapit-cdk/userpool-domain
# or
npm install @reapit-cdk/userpool-domain --save-dev
```

## Usage
```ts
import { CfnOutput, Stack, App } from 'aws-cdk-lib'
import { UserPool } from 'aws-cdk-lib/aws-cognito'
import { UserPoolDomain } from '@reapit-cdk/userpool-domain'

const app = new App()
const stack = new Stack(app, 'stack-name')
const userPool = UserPool.fromUserPoolId(stack, 'userpool', userPoolId)
const userPoolDomain = new UserPoolDomain(stack, 'domain', { userPool })
new CfnOutput(stack, 'userPoolDomain', {
value: userPoolDomain.domain,
})
```
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,7 @@ __metadata:
resolution: "@reapit-cdk/custom-resource-wrapper@workspace:packages/custom-resource-wrapper"
dependencies:
"@reapit-cdk/eslint": "workspace:^"
"@reapit-cdk/tsup": "workspace:^"
"@reapit-cdk/version-package": "workspace:^"
"@types/aws-lambda": ^8.10.121
aws-lambda: 1.0.7
Expand Down

0 comments on commit 77528e8

Please sign in to comment.