Skip to content

Commit

Permalink
feat(aws-iot-lambda-dynamodb): add vpc and environment variable name …
Browse files Browse the repository at this point in the history
…to construct interface (#894)

* Changes planned

* Initial implentation
  • Loading branch information
biffgaut authored Feb 9, 2023
1 parent 902c97c commit 8ee687a
Show file tree
Hide file tree
Showing 5 changed files with 1,078 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as iot from 'aws-cdk-lib/aws-iot';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import { IotToLambda } from '@aws-solutions-constructs/aws-iot-lambda';
import { LambdaToDynamoDB } from '@aws-solutions-constructs/aws-lambda-dynamodb';
Expand Down Expand Up @@ -54,13 +55,34 @@ export interface IotToLambdaToDynamoDBProps {
*
* @default - Read/write access is given to the Lambda function if no value is specified.
*/
readonly tablePermissions?: string
readonly tablePermissions?: string,
/**
* Optional Name for the Lambda function environment variable set to the name of the DynamoDB table.
*
* @default - DDB_TABLE_NAME
*/
readonly tableEnvironmentVariableName?: string;
/**
* An existing VPC for the construct to use (construct will NOT create a new VPC in this case)
*/
readonly existingVpc?: ec2.IVpc;
/**
* Properties to override default properties if deployVpc is true
*/
readonly vpcProps?: ec2.VpcProps;
/**
* Whether to deploy a new VPC
*
* @default - false
*/
readonly deployVpc?: boolean;
}

export class IotToLambdaToDynamoDB extends Construct {
public readonly iotTopicRule: iot.CfnTopicRule;
public readonly lambdaFunction: lambda.Function;
public readonly dynamoTable: dynamodb.Table;
public readonly vpc?: ec2.IVpc;

/**
* @summary Constructs a new instance of the IotToLambdaToDynamoDB class.
Expand All @@ -80,17 +102,26 @@ export class IotToLambdaToDynamoDB extends Construct {
defaults.CheckListValues(['All', 'Read', 'ReadWrite', 'Write'], [props.tablePermissions], 'table permission');
}

// Setup the IotToLambda
const iotToLambda = new IotToLambda(this, 'IotToLambda', props);
this.iotTopicRule = iotToLambda.iotTopicRule;
this.lambdaFunction = iotToLambda.lambdaFunction;

// Setup the LambdaToDynamoDB
const lambdaToDynamoDB = new LambdaToDynamoDB(this, 'LambdaToDynamoDB', {
tablePermissions: props.tablePermissions,
existingLambdaObj: this.lambdaFunction,
dynamoTableProps: props.dynamoTableProps
existingLambdaObj: props.existingLambdaObj,
lambdaFunctionProps: props.lambdaFunctionProps,
dynamoTableProps: props.dynamoTableProps,
tableEnvironmentVariableName: props.tableEnvironmentVariableName,
existingVpc: props.existingVpc,
deployVpc: props.deployVpc,
vpcProps: props.vpcProps,
});
this.dynamoTable = lambdaToDynamoDB.dynamoTable;
this.vpc = lambdaToDynamoDB.vpc;

// Setup the IotToLambda
const iotToLambda = new IotToLambda(this, 'IotToLambda', {
existingLambdaObj: lambdaToDynamoDB.lambdaFunction,
iotTopicRuleProps: props.iotTopicRuleProps
});
this.iotTopicRule = iotToLambda.iotTopicRule;
this.lambdaFunction = iotToLambda.lambdaFunction;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Resources": {
"testiotlambdadynamodbstackIotToLambdaLambdaFunctionServiceRoleC57F7FDA": {
"testiotlambdadynamodbstackLambdaToDynamoDBLambdaFunctionServiceRole31915E05": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
Expand Down Expand Up @@ -55,7 +55,7 @@
]
}
},
"testiotlambdadynamodbstackIotToLambdaLambdaFunctionServiceRoleDefaultPolicyB43AD823": {
"testiotlambdadynamodbstackLambdaToDynamoDBLambdaFunctionServiceRoleDefaultPolicy2B35234F": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyDocument": {
Expand Down Expand Up @@ -99,10 +99,10 @@
],
"Version": "2012-10-17"
},
"PolicyName": "testiotlambdadynamodbstackIotToLambdaLambdaFunctionServiceRoleDefaultPolicyB43AD823",
"PolicyName": "testiotlambdadynamodbstackLambdaToDynamoDBLambdaFunctionServiceRoleDefaultPolicy2B35234F",
"Roles": [
{
"Ref": "testiotlambdadynamodbstackIotToLambdaLambdaFunctionServiceRoleC57F7FDA"
"Ref": "testiotlambdadynamodbstackLambdaToDynamoDBLambdaFunctionServiceRole31915E05"
}
]
},
Expand All @@ -117,7 +117,7 @@
}
}
},
"testiotlambdadynamodbstackIotToLambdaLambdaFunctionDFEAF894": {
"testiotlambdadynamodbstackLambdaToDynamoDBLambdaFunction5165A7EE": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
Expand All @@ -128,7 +128,7 @@
},
"Role": {
"Fn::GetAtt": [
"testiotlambdadynamodbstackIotToLambdaLambdaFunctionServiceRoleC57F7FDA",
"testiotlambdadynamodbstackLambdaToDynamoDBLambdaFunctionServiceRole31915E05",
"Arn"
]
},
Expand All @@ -147,8 +147,8 @@
}
},
"DependsOn": [
"testiotlambdadynamodbstackIotToLambdaLambdaFunctionServiceRoleDefaultPolicyB43AD823",
"testiotlambdadynamodbstackIotToLambdaLambdaFunctionServiceRoleC57F7FDA"
"testiotlambdadynamodbstackLambdaToDynamoDBLambdaFunctionServiceRoleDefaultPolicy2B35234F",
"testiotlambdadynamodbstackLambdaToDynamoDBLambdaFunctionServiceRole31915E05"
],
"Metadata": {
"cfn_nag": {
Expand All @@ -169,13 +169,13 @@
}
}
},
"testiotlambdadynamodbstackIotToLambdaLambdaFunctionAwsIotLambdaInvokePermission1CF07890C": {
"testiotlambdadynamodbstackLambdaToDynamoDBLambdaFunctionAwsIotLambdaInvokePermission13FCFED39": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Fn::GetAtt": [
"testiotlambdadynamodbstackIotToLambdaLambdaFunctionDFEAF894",
"testiotlambdadynamodbstackLambdaToDynamoDBLambdaFunction5165A7EE",
"Arn"
]
},
Expand All @@ -188,28 +188,6 @@
}
}
},
"testiotlambdadynamodbstackIotToLambdaIotTopic74F5E3BB": {
"Type": "AWS::IoT::TopicRule",
"Properties": {
"TopicRulePayload": {
"Actions": [
{
"Lambda": {
"FunctionArn": {
"Fn::GetAtt": [
"testiotlambdadynamodbstackIotToLambdaLambdaFunctionDFEAF894",
"Arn"
]
}
}
}
],
"Description": "Processing of DTC messages from the AWS Connected Vehicle Solution.",
"RuleDisabled": false,
"Sql": "SELECT * FROM 'connectedcar/dtc/#'"
}
}
},
"testiotlambdadynamodbstackLambdaToDynamoDBDynamoTableE17E5733": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
Expand All @@ -235,6 +213,28 @@
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"testiotlambdadynamodbstackIotToLambdaIotTopic74F5E3BB": {
"Type": "AWS::IoT::TopicRule",
"Properties": {
"TopicRulePayload": {
"Actions": [
{
"Lambda": {
"FunctionArn": {
"Fn::GetAtt": [
"testiotlambdadynamodbstackLambdaToDynamoDBLambdaFunction5165A7EE",
"Arn"
]
}
}
}
],
"Description": "Processing of DTC messages from the AWS Connected Vehicle Solution.",
"RuleDisabled": false,
"Sql": "SELECT * FROM 'connectedcar/dtc/#'"
}
}
}
},
"Parameters": {
Expand Down
Loading

0 comments on commit 8ee687a

Please sign in to comment.