Skip to content

Commit

Permalink
Merge pull request #178 from mbonig/feat/making-connectable
Browse files Browse the repository at this point in the history
feat: now DatabaseScript exposes the underlying connectable
  • Loading branch information
mbonig authored Jan 6, 2022
2 parents b5b6a9a + 7239b00 commit 0c17175
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 10 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Name|Description



__Implements__: [IConstruct](#constructs-iconstruct), [IDependable](#constructs-idependable)
__Implements__: [IConstruct](#constructs-iconstruct), [IDependable](#constructs-idependable), [aws_ec2.IConnectable](#aws-cdk-lib-aws-ec2-iconnectable)
__Extends__: [Construct](#constructs-construct)

### Initializer
Expand All @@ -41,10 +41,18 @@ new DatabaseScript(scope: Construct, id: string, props: DatabaseScriptProps)
* **vpc** (<code>[aws_ec2.IVpc](#aws-cdk-lib-aws-ec2-ivpc)</code>) The VPC for the Lambda Function to attach to. __*Optional*__



### Properties


Name | Type | Description
-----|------|-------------
**connections** | <code>[aws_ec2.Connections](#aws-cdk-lib-aws-ec2-connections)</code> | The network connections associated with this resource.

### Methods


#### bind(securityGroup, port) <a id="matthewbonig-rds-tools-databasescript-bind"></a>
#### bind(securityGroup, port)⚠️ <a id="matthewbonig-rds-tools-databasescript-bind"></a>

Grants access to the Lambda Function to the given SecurityGroup.

Expand Down
11 changes: 9 additions & 2 deletions src/DatabaseScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Duration,
Stack,
} from 'aws-cdk-lib';
import { Connections, IConnectable } from 'aws-cdk-lib/aws-ec2';
import { Construct } from 'constructs';

export interface DatabaseScriptProps {
Expand Down Expand Up @@ -49,7 +50,8 @@ export interface DatabaseScriptProps {
readonly script: string;
}

export class DatabaseScript extends Construct {
export class DatabaseScript extends Construct implements IConnectable {

private handler: aws_lambda.IFunction;

constructor(scope: Construct, id: string, props: DatabaseScriptProps) {
Expand Down Expand Up @@ -81,7 +83,6 @@ export class DatabaseScript extends Construct {
logRetention: aws_logs.RetentionDays.ONE_DAY,
});


const assetPath = path.join(__dirname, 'layer');

handler.addLayers(new aws_lambda.LayerVersion(this, 'deps-layer', {
Expand Down Expand Up @@ -134,9 +135,15 @@ export class DatabaseScript extends Construct {
});
}

get connections(): Connections {
return this.handler.connections;
}


/**
* Grants access to the Lambda Function to the given SecurityGroup.
* Adds an ingress rule to the given security group and for the given port.
* @deprecated Do not use, pass this construct as an IConnectable
* @param securityGroup
* @param port
*/
Expand Down

0 comments on commit 0c17175

Please sign in to comment.