Skip to content

Commit

Permalink
dynamodb initial iac
Browse files Browse the repository at this point in the history
  • Loading branch information
NicklausBrain committed Sep 18, 2021
1 parent 8f6e9e1 commit b20df0a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
18 changes: 16 additions & 2 deletions snake-iac/lib/snake-iac-stack.ts
Expand Up @@ -5,6 +5,7 @@ import * as rg from '@aws-cdk/aws-resourcegroups';
import * as gate from '@aws-cdk/aws-apigatewayv2';
import * as lambda from '@aws-cdk/aws-lambda';
import * as integration from '@aws-cdk/aws-apigatewayv2-integrations'
import * as dynamodb from '@aws-cdk/aws-dynamodb';
import { env } from 'process';

const envName = env.NODE_ENV || 'temp';
Expand Down Expand Up @@ -40,6 +41,9 @@ export class SnakeStack extends cdk.Stack {
handler: "lambda.handler",
memorySize: 512,
timeout: cdk.Duration.seconds(3),
environment: { // environment variables for lambda app
NODE_ENV: envName,
}
});

// API Gateway
Expand Down Expand Up @@ -72,12 +76,22 @@ export class SnakeStack extends cdk.Stack {
integration: snakeApiIntegration
});

// Tags
// Persistence layer
const table = new dynamodb.Table(this, nameIt('DynamoDb-Table'), {
tableName: nameIt('DynamoDb-Table'),
partitionKey: { name: 'ipAddress', type: dynamodb.AttributeType.STRING },
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
removalPolicy: cdk.RemovalPolicy.DESTROY // remove on stack destruction
});

table.grantReadWriteData(apiLambda); // give api access to data

// Tags (to improve resources distinction)
for (const nodeChild of scope.node.children) {
cdk.Tags.of(nodeChild).add(SnakeStack.Name, SnakeStack.Name);
}

// Resource group
// Resource group (akin to azure)
new rg.CfnGroup(this, nameIt("resource-group"), {
name: nameIt("resource-group"),
tags: [{ key: SnakeStack.Name, value: SnakeStack.Name }],
Expand Down
29 changes: 29 additions & 0 deletions snake-iac/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions snake-iac/package.json
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"@aws-cdk/aws-apigatewayv2": "^1.120.0",
"@aws-cdk/aws-apigatewayv2-integrations": "^1.120.0",
"@aws-cdk/aws-dynamodb": "^1.120.0",
"@aws-cdk/aws-resourcegroups": "^1.120.0",
"@aws-cdk/aws-s3": "^1.120.0",
"@aws-cdk/aws-s3-deployment": "^1.120.0",
Expand Down

0 comments on commit b20df0a

Please sign in to comment.