GithubHelp home page GithubHelp logo

nanodeath / hellolambdacdktemplate Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 260 KB

Template package preconfigured for Java 17 Lambdas and CDK TypeScript.

Kotlin 28.69% Java 26.05% JavaScript 8.94% TypeScript 36.32%

hellolambdacdktemplate's Introduction

Hello Lambda CDK Template

You’ve found the easiest way to get started deploying a Java Lambda-based stack using the AWS CDK! Well, easier than some ways. Probably.

What can it do?

This template is using the following tech:

  • Java 17, the latest Java LTS which is now supported on AWS Lambda.

  • AWS CDK, the AWS-official infrastructure-as-code option. Using TypeScript!

  • Gradle 8, for the latest build mojo. Using the new Kotlin syntax.

  • ESLint and Prettier, to keep your CDK TypeScript looking spiffy.

  • Spotless, to keep your Java code, well…​spotless.

This template is for Java, but Kotlin support is easy to enable by uncommenting the marked bits in the build.gradle.kts file.

What doesn’t it do?

  • It doesn’t create native images, which could help with cold starts.

  • It doesn’t do anything with frontend. You’re on your own for that.

  • It doesn’t include authentication or DDoS/bot mitigation.

Prerequisites 📋

Still with me? Great, here’s your preflight checklist (commands to be run in your terminal):

  • java -version — running this should print out a version string for Java 17. Otherwise, you’ll need to find and install it.

  • node --version — running this should print out a v18 version string, like v18.16.0. If not, consider using something like nvm to install and use Node. You’re also assumed to have npm on your path.

  • cdk --version — running this should print out a 2.x version string, like 2.85.0 (build 4e0d726). If not, directions for installing it are linked from the CDK Setup section just below.

At this point you should have each of those CLI applications on your path, and running the above commands should print out sane values.

CDK Setup

Since this template deploys to an AWS account from your terminal, you’ll need to do some setup to ensure the build logic can invoke the CDK CLI successfully.

Follow the official CDK Getting Started guide, bearing in mind this template uses TypeScript for the CDK portion.

You’ll need to set up authentication (via aws configure sso) and bootstrap the account (using the described cdk bootstrap command).

AWS SSO Login

After the setup is complete, you’ll periodically need to run:

aws sso login

to refresh your session. If your profile has a name (which the CLI recommends), make sure to export the name to an environment variable, so commands that expect a profile can use it without passing a parameter:

# use your profile name instead
# on Mac and Linux:
export AWS_PROFILE=hellolambda

Alternatively, you can update aws.profile in gradle.properties to point to your profile.

🚀🚀 Time to Deploy! 🚀🚀

This repository is a GitHub template. To use this template, click the big green Use this template button near the top of this page. This will create a brand new repository with a fresh commit history in your own account. You can then clone that repository as usual to continue.

Important
By default, the deployed stack will be called "SampleStack" and deployed into the us-west-2 region. If this is undesirable to you, change the configuration in cdk.ts now.

Gradle tasks have been registered that make it easy to compile and zip your Java code and deploy it in a single line.

Just run:

./gradlew deploy

This will deploy the new CloudFormation stack into your AWS account. It should take a bit under 2 minutes, but future deployments will often be faster.

Hotswapping is also supported and recommended for rapid Lambda development:

./gradlew deployHotswap

Alternatively, for more control, you can invoke the cdk command directly from inside the cdk subdirectory. Just make sure you run ./gradlew buildZip from the package root to compile and package any Java changes, first.

What’s here? 👀

There are:

Cost 💸

Cost should be negligible (under $1 USD/mo) until you make significant changes. As the license implies, this template nor its authors are responsible for any costs you incur by using this template. You can monitor your AWS spend in the Billing Dashboard,

Where to go from here? 🏗

If you want to create more lambdas, jump into the app code and create new handlers there. If you want to create new AWS infra, update the CDK code using the many official and unofficial constructs.

Feel free to delete this file whenever you’re ready, or better yet, replace it with your own README. (or a README.md)

That should be it. Happy developing!

Tear down 👋😢

If you want to destroy the stacks created by this template, you can either go into the cdk directory and run cdk destroy, or you can navigate to CloudFormation in the AWS Console and destroy the stack created there (called SampleStack by default).

After stack teardown is complete, display Deleted stacks in the CloudFormation console and select the stack you just deleted. In the Resources tab, if there are any resources that aren’t DELETE_COMPLETE, you may need to delete those resources manually.

License 👮

This project is licensed under the MIT License.

(A LICENSE file isn’t present because this repository is meant to be used as a template, and I don’t want users to accidentally MIT-license code created from this template.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.