Our solutions are purely cloud-based, we need to develop infrastructure as a code
Applicable when
- Creating the infrastructure for AWS rewrites
Non-applicable when
- Creating the infrastructure for Microsoft Azure, Google Cloud
Implementation
CDK allows you to define all the resources you need for your application: User pools, Lambda functions, S3 buckets, SQS queues, etc.
You do it in a programming language, e.g. TypeScript.
Each resource is defined as a variable:
const bucket = new Bucket(this, 'BucketName', { bucketName: 'BucketName', });
Resources are grouped into stacks according to their usage:
import * as cdk from '@aws-cdk/core'; import * as lambda from '@aws-cdk/aws-lambda'; import * as apigw from '@aws-cdk/aws-apigateway'; export class CdkWorkshopStack extends cdk.Stack { constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { super(scope, id, props); // defines an AWS Lambda resource const hello = new lambda.Function(this, 'HelloHandler', { // execution environment code: runtime: lambda.Runtime.NODEJS_10_X, // code loaded from "lambda" directory code: lambda.Code.fromAsset('lambda'), //function is "handler" handler: 'hello.handler' }); // defines an API Gateway REST API resource //backed by our "hello" function. new apigw.LambdaRestApi(this, 'Endpoint', { handler: hello}); } }
You can easily bypass the AWS limits of 200 resources per stack splitting the stacks and defining the next stacks.
To properly define the resources specific to the project you need to familiarize yourself with the list of available constructs and their properties in CDK documentation.
We recommend you to take the simple workshop to get hands-on experience creating basic cloud applications with CDK.
Related articles:
Comments
0 comments
Please sign in to leave a comment.