Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: remove '@aws-cdk/aws-custom-resources' #513

Merged
merged 6 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion packages/@aws-cdk/aws-cloudformation/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,68 @@
## CDK Constructs for AWS CloudFormation
This module is part of the [AWS Cloud Development Kit](https://github.com/awslabs/aws-cdk) project.
This module is part of the [AWS Cloud Development Kit](https://github.com/awslabs/aws-cdk) project.

### Custom Resources

Custom Resources are CloudFormation resources that are implemented by
arbitrary user code. They can do arbitrary lookups or modifications
during a CloudFormation synthesis run.

You will typically use Lambda to implement a Construct implemented as a
Custom Resource (though SNS topics can be used as well). Your Lambda function
will be sent a `CREATE`, `UPDATE` or `DELETE` message, depending on the
CloudFormation life cycle, and can return any number of output values which
will be available as attributes of your Construct. In turn, those can
be used as input to other Constructs in your model.

In general, consumers of your Construct will not need to care whether
it is implemented in term of other CloudFormation resources or as a
custom resource.

Note: when implementing your Custom Resource using a Lambda, use
a `SingletonLambda` so that even if your custom resource is instantiated
multiple times, the Lambda will only get uploaded once.

#### Example

Sample of a Custom Resource that copies files into an S3 bucket during deployment
(implementation of actual `copy.py` operation elided).

```ts
interface CopyOperationProps {
sourceBucket: IBucket;
targetBucket: IBucket;
}

class CopyOperation extends Construct {
constructor(parent: Construct, name: string, props: DemoResourceProps) {
super(parent, name);

const lambdaProvider = new SingletonLambda(this, 'Provider', {
uuid: 'f7d4f730-4ee1-11e8-9c2d-fa7ae01bbebc',
code: new LambdaInlineCode(resources['copy.py']),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should provide an example that uses assets here?

handler: 'index.handler',
timeout: 60,
runtime: LambdaRuntime.Python3,
});

new CustomResource(this, 'Resource', {
lambdaProvider,
properties: {
sourceBucketArn: props.sourceBucket.bucketArn,
targetBucketArn: props.targetBucket.bucketArn,
}
});
}
}
```

More examples are in the `example` directory, including an example of how to use
the `cfnresponse` module that is provided for you by CloudFormation.

#### References

See the following section of the docs on details to write Custom Resources:

* [Introduction](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html)
* [Reference](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref.html)
* [Code Reference](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cloudformation } from '@aws-cdk/aws-cloudformation';
import lambda = require('@aws-cdk/aws-lambda');
import sns = require('@aws-cdk/aws-sns');
import cdk = require('@aws-cdk/cdk');
import { cloudformation } from './cloudformation.generated';

/**
* Collection of arbitrary properties
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudformation/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// AWS::CloudFormation CloudFormation Resources:
export * from './cloudformation.generated';
export * from './custom-resource';
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-cloudformation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@
"devDependencies": {
"@aws-cdk/assert": "^0.8.1",
"cdk-build-tools": "^0.8.1",
"cdk-integ-tools": "^0.8.1",
"cfn2ts": "^0.8.1",
"pkglint": "^0.8.1"
},
"dependencies": {
"@aws-cdk/cdk": "^0.8.1"
"@aws-cdk/cdk": "^0.8.1",
"@aws-cdk/aws-lambda": "^0.8.1",
"@aws-cdk/aws-sns": "^0.8.1"
},
"homepage": "https://github.com/awslabs/aws-cdk"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import lambda = require('@aws-cdk/aws-lambda');
import cdk = require('@aws-cdk/cdk');
import fs = require('fs');
import customResource = require('../lib');
import cloudformation = require('../lib');

interface DemoResourceProps {
/**
Expand All @@ -21,8 +21,8 @@ class DemoResource extends cdk.Construct {
constructor(parent: cdk.Construct, name: string, props: DemoResourceProps) {
super(parent, name);

const resource = new customResource.CustomResource(this, 'Resource', {
lambdaProvider: new customResource.SingletonLambda(this, 'Singleton', {
const resource = new cloudformation.CustomResource(this, 'Resource', {
lambdaProvider: new lambda.SingletonLambda(this, 'Singleton', {
uuid: 'f7d4f730-4ee1-11e8-9c2d-fa7ae01bbebc',
// This makes the demo only work as top-level TypeScript program, but that's fine for now
code: new lambda.LambdaInlineCode(fs.readFileSync('integ.trivial-lambda-provider.py', { encoding: 'utf-8' })),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from '@aws-cdk/assert';
import lambda = require('@aws-cdk/aws-lambda');
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
import { CustomResource, SingletonLambda } from '../lib';
import { CustomResource } from '../lib';

// tslint:disable:object-literal-key-quotes

Expand Down Expand Up @@ -92,7 +92,7 @@ class TestCustomResource extends cdk.Construct {
constructor(parent: cdk.Construct, name: string) {
super(parent, name);

const singletonLambda = new SingletonLambda(this, 'Lambda', {
const singletonLambda = new lambda.SingletonLambda(this, 'Lambda', {
uuid: 'TestCustomResourceProvider',
code: new lambda.LambdaInlineCode('def hello(): pass'),
runtime: lambda.LambdaRuntime.Python27,
Expand Down
13 changes: 0 additions & 13 deletions packages/@aws-cdk/aws-custom-resources/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions packages/@aws-cdk/aws-custom-resources/.npmignore

This file was deleted.

201 changes: 0 additions & 201 deletions packages/@aws-cdk/aws-custom-resources/LICENSE

This file was deleted.

2 changes: 0 additions & 2 deletions packages/@aws-cdk/aws-custom-resources/NOTICE

This file was deleted.

Loading