AWS Articlesdevelopment

AWS PDK - Spin up AWS Projects in minutes

By Johannes Hayer
Picture of the author
Published on
pdk

AWS Project Development Kit (AWS PDK), a robust framework that's transforming how we approach AWS cloud project development. In this post, I'll dive into the AWS PDK, exploring its features, capabilities, and how it can significantly enhance your cloud development workflow.

What is the AWS PDK?

The AWS PDK stands as a cornerstone in cloud project development, offering a suite of building blocks for common patterns and a set of development tools for efficient project management. This kit allows developers to define projects programmatically using type-safe constructs in TypeScript, Python, or Java, offering a myriad of benefits:

  1. Rapid Project Setup: The AWS PDK enables quick project initialization, complete with pre-configured boilerplates.
  2. Continuous Updates: It offers seamless updates to existing projects, including new versions of dependencies and lint configurations.
  3. Polyglot Monorepos: With the AWS PDK, building polyglot monorepos becomes effortless, featuring build caching, cross-language build dependencies, dependency visualization, and more.
  4. Codified Patterns: It allows leveraging codified patterns that vend both project and infrastructure (CDK) code.

Built atop Projen, the AWS PDK requires all constructs to be defined via a projenrc file, ensuring a structured and standardized approach to project setup.

Why AWS PDK?

The AWS PDK isn't just a tool; it's a paradigm shift in cloud project development. To illustrate, let's look at a code snippet from a projenrc file that sets up a polyglot monorepo, incorporating a React website with Cognito Auth and a Smithy Type Safe API.

import { CloudscapeReactTsWebsiteProject } from "@aws/pdk/cloudscape-react-ts-website";
import { InfrastructureTsProject } from "@aws/pdk/infrastructure";
import { MonorepoTsProject } from "@aws/pdk/monorepo";
import {
    DocumentationFormat,
    Language,
    Library,
    ModelLanguage,
    TypeSafeApiProject,
} from "@aws/pdk/type-safe-api";
import { javascript } from "projen";

const monorepo = new MonorepoTsProject({
    name: "my-project",
    packageManager: javascript.NodePackageManager.PNPM,
    projenrcTs: true,
});

const api = new TypeSafeApiProject({
    parent: monorepo,
    outdir: "packages/api",
    name: "myapi",
    infrastructure: {
        language: Language.TYPESCRIPT,
    },
    model: {
        language: ModelLanguage.SMITHY,
        options: {
        smithy: {
            serviceName: {
            namespace: "com.aws",
            serviceName: "MyApi",
            },
        },
        },
    },
    runtime: {
        languages: [Language.TYPESCRIPT],
    },
    documentation: {
        formats: [DocumentationFormat.HTML_REDOC],
    },
    library: {
        libraries: [Library.TYPESCRIPT_REACT_QUERY_HOOKS],
    },
    handlers: {
        languages: [Language.TYPESCRIPT],
    },
});

const website = new CloudscapeReactTsWebsiteProject({
    parent: monorepo,
    outdir: "packages/website",
    name: "website",
    typeSafeApi: api,
});

new InfrastructureTsProject({
    parent: monorepo,
    outdir: "packages/infra",
    name: "infra",
    cloudscapeReactTsWebsite: website,
    typeSafeApi: api,
});

monorepo.synth();

This concise piece of code lays the foundation for a fully-operational AWS application, generating necessary source code, packages, and infrastructure. The beauty lies in the simplicity and efficiency of the process – write the code, build, and deploy!

The Outcome of AWS PDK's Magic

From the above example, the AWS PDK seamlessly creates several interconnected components:

  1. Monorepo: Manages interdependencies and offers build caching and dependency visualization.
  2. API/Model: Enables defining APIs using Smithy or OpenAPI IDL.
  3. API/Documentation: Automatically produces API documentation in various formats.
  4. API/Infrastructure: Generates API infrastructure constructs in a type-safe manner.
  5. API/Libraries: Creates a React hooks library for easy API interaction.
  6. API/Runtime: Contains server bindings for type-safe handlers.
  7. API/Handlers: Generates handler stubs with built-in type safety and additional features.
  8. Website: Sets up a React website integrated with Cognito Auth and the API.
  9. Infra: Establishes all necessary CDK infrastructure, including auto-generated diagrams.

Development with AWS PDK

Getting started with the AWS PDK is straightforward. The Developer Guide provides code samples in all supported languages, ensuring a smooth initiation regardless of your preferred programming language.

Contributing to AWS PDK

Given its open-source nature, the AWS PDK welcomes contributions. This collaborative approach not only enhances the toolkit but also fosters a community of innovative cloud developers.

Conclusion

The AWS PDK is more than just a development kit; it's a gateway to efficient, streamlined, and integrated cloud project development. It offers an unparalleled opportunity to focus on what truly matters in your projects, reducing the overhead of repetitive setup tasks. As a cloud enthusiast, I recommend exploring the AWS PDK for your next AWS project. It's not just a tool; it's a game-changer in the realm of inital cloud setup.

https://aws.github.io/aws-pdk/overview/index.html

Stay Tuned

Subscribe for development and indie hacking tips!