Skip to content

Commit

Permalink
Update to version v1.79.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hnishar committed Dec 31, 2020
1 parent 15300ed commit 8130c54
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/slack-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Issue Slack Notification
if: github.event_name == 'issues' || github.event_name == 'issue_comment'
if: ${{ github.event_name == 'issues' || (!github.event.issue.pull_request && github.event_name == 'issue_comment') }}
uses: 8398a7/action-slack@v3
with:
status: custom
Expand All @@ -33,7 +33,7 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
- name: PR Slack Notification
if: github.event_name == 'pull_request'
if: ${{ github.event_name == 'pull_request' || (github.event.issue.pull_request && github.event_name == 'issue_comment') }}
uses: 8398a7/action-slack@v3
with:
status: custom
Expand All @@ -47,10 +47,10 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
PR_NUMBER: ${{ github.event.number }}
- name: Set env
if: github.event_name == 'release'
if: ${{ github.event_name == 'release' }}
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Release Slack Notification
if: github.event_name == 'release'
if: ${{ github.event_name == 'release' }}
uses: 8398a7/action-slack@v3
with:
status: custom
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## 1.79.0 (2020-12-31)

### Changed
- Upgraded all patterns to CDK v1.79.0
- Fixed the override warning bug for `aws-lambda-step-function` pattern ([#108](https://github.com/awslabs/aws-solutions-constructs/issues/108))
- Updated `aws-lambda-sqs` construct props `existingVpc` from `ec2.Vpc` to `ec2.IVpc`

## 1.78.0 (2020-12-22)

### Changed
Expand Down
2 changes: 1 addition & 1 deletion source/lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"./patterns/@aws-solutions-constructs/*"
],
"rejectCycles": "true",
"version": "1.78.0"
"version": "1.79.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,23 @@ _Parameters_
|deployDeadLetterQueue?|`boolean`|Whether to create a secondary queue to be used as a dead letter queue. Defaults to `true`.|
|deadLetterQueueProps?|[`sqs.QueueProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sqs.QueueProps.html)|Optional user-provided props to override the default props for the dead letter queue. Only used if the `deployDeadLetterQueue` property is set to true.|
|maxReceiveCount?|`number`|The number of times a message can be unsuccessfully dequeued before being moved to the dead letter queue. Defaults to `15`.|
|existingVpc?|`ec2.Vpc`|An optional, existing VPC into which this construct should be deployed. When deployed in a VPC, the Lambda function will use ENIs in the VPC to access network resources and an Interface Endpoint will be created in the VPC for Amazon SQS. If an existing VPC is provided, the `deployVpc` property cannot be `true`|
|deployVpc?|`boolean`|Whether to create a new VPC based on `vpcProps` into which to deploy this construct. Setting this to true will deploy the minimal, most private VPC to run the construct:
|existingVpc?|[`ec2.IVpc`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.IVpc.html)|An optional, existing VPC into which this pattern should be deployed. When deployed in a VPC, the Lambda function will use ENIs in the VPC to access network resources and an Interface Endpoint will be created in the VPC for Amazon SQS. If an existing VPC is provided, the `deployVpc` property cannot be `true`. This uses `ec2.IVpc` to allow clients to supply VPCs that exist outside the stack using the [`ec2.Vpc.fromLookup()`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.Vpc.html#static-fromwbrlookupscope-id-options) method.|
|deployVpc?|`boolean`|Whether to create a new VPC based on `vpcProps` into which to deploy this pattern. Setting this to true will deploy the minimal, most private VPC to run the pattern:

* One isolated subnet in each Availability Zone used by the CDK program
* `enableDnsHostnames` and `enableDnsSupport` will both be set to true

If this property is `true` then `existingVpc` cannot be specified. Defaults to `false`.|
|vpcProps?|`ec2.VpcProps`|Optional user-provided properties to override the default properties for the new VPC. `enableDnsHostnames`, `enableDnsSupport`, `natGateways` and `subnetConfiguration` are set by the Construct, so any values for those properties supplied here will be overrriden. If `deployVpc` is not `true` then this property will be ignored.|
|vpcProps?|`ec2.VpcProps`|Optional user-provided properties to override the default properties for the new VPC. `enableDnsHostnames`, `enableDnsSupport`, `natGateways` and `subnetConfiguration` are set by the pattern, so any values for those properties supplied here will be overrriden. If `deployVpc` is not `true` then this property will be ignored.|

## Pattern Properties

| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of the Lambda function created by the pattern.|
|sqsQueue|[`sqs.Queue`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sqs.Queue.html)|Returns an instance of the SQS queue created by the pattern. |
|deadLetterQueue?|[`sqs.Queue`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sqs.Queue.html)|Returns an instance of the dead letter queue created by the pattern, if one is deployed.|
|vpc?|[`ec2.IVpc`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.IVpc.html)|Returns an interface on the VPC used by the pattern (if any). This may be a VPC created by the pattern or the VPC supplied to the pattern constructor.|

## Default settings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface LambdaToSqsProps {
/**
* An existing VPC for the construct to use (construct will NOT create a new VPC in this case)
*/
readonly existingVpc?: ec2.Vpc;
readonly existingVpc?: ec2.IVpc;
/**
* Properties to override default properties if deployVpc is true
*/
Expand All @@ -94,7 +94,7 @@ export class LambdaToSqs extends Construct {
public readonly lambdaFunction: lambda.Function;
public readonly sqsQueue: sqs.Queue;
public readonly deadLetterQueue?: sqs.DeadLetterQueue;
public readonly vpc?: ec2.Vpc;
public readonly vpc?: ec2.IVpc;

/**
* @summary Constructs a new instance of the LambdaToSqs class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,38 @@ test("Test minimal deployment with an existing VPC", () => {
});
});

// --------------------------------------------------------------
// Test minimal deployment with an existing VPC and existing Lambda function not in a VPCs
//
// buildLambdaFunction should throw an error if the Lambda function is not
// attached to a VPC
// --------------------------------------------------------------
test("Test minimal deployment with an existing VPC and existing Lambda function not in a VPC", () => {
// Stack
const stack = new Stack();

const testLambdaFunction = new lambda.Function(stack, 'test-lamba', {
runtime: lambda.Runtime.NODEJS_10_X,
handler: "index.handler",
code: lambda.Code.fromAsset(`${__dirname}/lambda`),
});

const testVpc = new ec2.Vpc(stack, "test-vpc", {});

// Helper declaration
const app = () => {
// Helper declaration
new LambdaToSqs(stack, "lambda-to-sqs-stack", {
existingLambdaObj: testLambdaFunction,
existingVpc: testVpc,
});
};

// Assertion
expect(app).toThrowError();

});

// --------------------------------------------------------------
// Test bad call with existingVpc and deployVpc
// --------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface BuildLambdaFunctionProps {
*
* @default - none
*/
readonly vpc?: ec2.Vpc;
readonly vpc?: ec2.IVpc;
}

export function buildLambdaFunction(scope: cdk.Construct, props: BuildLambdaFunctionProps): lambda.Function {
Expand All @@ -48,14 +48,19 @@ export function buildLambdaFunction(scope: cdk.Construct, props: BuildLambdaFunc
throw Error('Either existingLambdaObj or lambdaFunctionProps is required');
}
} else {
if (props.vpc) {
if (!props.existingLambdaObj.isBoundToVpc) {
throw Error('A Lambda function must be bound to a VPC upon creation, it cannot be added to a VPC in a subsequent construct');
}
}
return props.existingLambdaObj;
}
}

export function deployLambdaFunction(scope: cdk.Construct,
lambdaFunctionProps: lambda.FunctionProps,
functionId?: string,
vpc?: ec2.Vpc): lambda.Function {
vpc?: ec2.IVpc): lambda.Function {

const _functionId = functionId ? functionId : 'LambdaFunction';
const _functionRoleId = _functionId + 'ServiceRole';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function flagOverriddenDefaults(defaultProps: object, userProps: object)
* 'Argument to Intrinsic must be a plain value object', so such props are excluded from the diff check.
*/
function _prefilter(_path: any[], _key: string): boolean {
const prefilters = ['maxRecordAge', 'expiration', 'transitionAfter'];
const prefilters = ['maxRecordAge', 'expiration', 'transitionAfter', 'destination', 'timeout'];

if (prefilters.indexOf(_key) >= 0) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function addPermissions(_role: iam.Role) {

}

export function buildSagemakerNotebook(scope: cdk.Construct, props: BuildSagemakerNotebookProps): [sagemaker.CfnNotebookInstance, ec2.Vpc?,
export function buildSagemakerNotebook(scope: cdk.Construct, props: BuildSagemakerNotebookProps): [sagemaker.CfnNotebookInstance, ec2.IVpc?,
ec2.SecurityGroup?] {
// Setup the notebook properties
let sagemakerNotebookProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface BuildVpcProps {
/**
* Existing instance of a VPC, if this is set then the all Props are ignored
*/
readonly existingVpc?: ec2.Vpc;
readonly existingVpc?: ec2.IVpc;
/**
* User provided props to override the default props for the VPC.
*/
Expand All @@ -32,7 +32,7 @@ export interface BuildVpcProps {
readonly constructVpcProps?: ec2.VpcProps;
}

export function buildVpc(scope: Construct, props?: BuildVpcProps): ec2.Vpc {
export function buildVpc(scope: Construct, props?: BuildVpcProps): ec2.IVpc {
if (props?.existingVpc) {
return props?.existingVpc;
}
Expand Down Expand Up @@ -116,7 +116,7 @@ const endpointSettings: EndpointDefinition[] = [

export function AddAwsServiceEndpoint(
scope: Construct,
vpc: ec2.Vpc,
vpc: ec2.IVpc,
interfaceTag: ServiceEndpointTypes
) {
if (!vpc.node.children.some((child) => child.node.id === interfaceTag)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,51 @@ test("Test for error if VPC in arguments AND in Lambda Function properties", ()

expect(app).toThrowError();
});

test("Test minimal deployment with an existing VPC and existing Lambda function not in a VPC", () => {
// Stack
const stack = new Stack();

const testLambdaFunction = new lambda.Function(stack, 'test-lamba', {
runtime: lambda.Runtime.NODEJS_10_X,
handler: "index.handler",
code: lambda.Code.fromAsset(`${__dirname}/lambda`),
});

const testVpc = new ec2.Vpc(stack, "test-vpc", {});

const app = () => {
defaults.buildLambdaFunction(stack, {
existingLambdaObj: testLambdaFunction,
vpc: testVpc,
});

};

// Assertion
expect(app).toThrowError();

});

test("Test minimal deployment with an existing VPC and existing Lambda function in a VPC", () => {
// Stack
const stack = new Stack();

const testVpc = new ec2.Vpc(stack, "test-vpc", {});

const testLambdaFunction = new lambda.Function(stack, 'test-lamba', {
runtime: lambda.Runtime.NODEJS_10_X,
handler: "index.handler",
code: lambda.Code.fromAsset(`${__dirname}/lambda`),
vpc: testVpc,
});

defaults.buildLambdaFunction(stack, {
existingLambdaObj: testLambdaFunction,
vpc: testVpc,
});

// All we're doing here is confirming that buildLambdaFunction does NOT
// throw an exception when the existing Lambda function is in a VPCs

});
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,31 @@ test('Test override warning on/off: undefined on', () => {
overrideProps(a, b);
// Assert
expect(warn).toBeCalledTimes(1);
});

// --------------------------------------------------------------
// Test current prefilters
// --------------------------------------------------------------
test('Test current prefilters', () => {
// Arrange
const a = {
destination: 'sampleDestinationValueA',
maxRecordAge: 'sampleMaxRecordAgeValueA',
expiration: 'sampleExpirationValueA',
transitionAfter: 'sampleTransitionValueA',
timeout: 'sampleTimeoutValueA'
};
const b = {
destination: 'sampleDestinationValueB',
maxRecordAge: 'sampleMaxRecordAgeValueB',
expiration: 'sampleExpirationValueB',
transitionAfter: 'sampleTransitionValueB',
timeout: 'sampleTimeoutValueB'
};
// Act
const warn = jest.spyOn(log, 'warn');
process.env.overrideWarningsEnabled = undefined;
overrideProps(a, b);
// Assert
expect(warn).toBeCalledTimes(0);
});

0 comments on commit 8130c54

Please sign in to comment.