How to use Amplify to Leverage AWS CDK with Cognito, Lambda, and API Gateway — Part 1

Amchelle C.
3 min readDec 2, 2020

AWS Amplify CLI is a great and easy way to integrate with AWS cloud services at a basic level. However, to really make your development secure and easy to replicate, the AWS Cloud Development Kit (AWS CDK) is your go to framework. CDK with Amplify is a powerful combination that can be a little difficult to establish so I wanted to create a step by step guide.

If you haven’t already, create an AWS account: https://aws.amazon.com/

Create an AWS account

  1. Got to top right corner click: “Create an AWS Account”
  2. Once, you have successfully signed in, go to the AWS IAM console and create a new user. Under Access management, click Users, then Add user.

3. Create user name and choose “Programmatic access”, then click “Next: Permissions” in the bottom right.

4. Continue creating the new user until you see your Access key ID and Secret access key. Keep this visible, we will need these for the next steps.

Set up environment

Now, let’s set up the CDK.

The AWS CDK has support for the following programming languages: TypeScript, JavaScript, Python, Java, and C#. For his tutorial I will use TypeScript.

I’m going to install the AWS CLI in order to configure our CDK credentials with AWS services for Linux. Use the following link to install on different operating systems.

https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html

  1. Open a terminal and install the AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

2. Use aws configure to set up your environment. It will require your access key ID and secret key from the previous AWS user creation step. Choose a default region (e.g. us-east-1, us-east-2, use-west-2).

aws configure

Now we are ready to create our CDK project!

Create CDK project

  1. Install the AWS CDK Toolkit
npm install -g aws-cdk

2. Create a new directory

mkdir cdk-example && cd cdk-example

3. Create a new TypeScript CDK project

cdk init example-app --language typescript

We have now successfully set up our CDK project and can begin writing the CDK code for deployment.

In Part 2, I’ll create a Cognito User Pool, Lambda function, and API Gateway endpoint to deploy to our AWS account.

--

--