Git Product home page Git Product logo

cdk-lambda-packaging-java's Introduction

cdk-lambda-packaging-java

Build status

This sample application show how you can use AWS Cloud Development Kit(AWS CDK) to deploy a AWS lambda functions with external dependencies. AWS Serverless Application Model (AWS SAM) takes care of building and packaging lambda function with external dependencies out of the box. It was not possible this with AWS CDK until s3-assets was introduced.

Assets are local files or directories which are needed by a CDK app. A common example is a directory which contains the handler code for a Lambda function, but assets can represent any artifact that is needed for the app's operation. When deploying a CDK app that includes constructs with assets, the CDK toolkit will first upload all the assets to S3, and only then deploy the stacks. The S3 locations of the uploaded assets will be passed in as CloudFormation Parameters to the relevant stacks.

When defining an asset, you can use the bundling option to specify a command to run inside a docker container. The command can read the contents of the asset source from /asset-input and is expected to write files under /asset-output (directories mapped inside the container). The files under /asset-output will be zipped and uploaded to S3 as the asset.

The cdk.json file inside infrastructure directory tells the CDK Toolkit how to execute your app.

It is a Maven based project, so you can open this project with any Maven compatible Java IDE to build and run tests.

Project structure

├── infrastructure          # Infrastructure code vi CDK(Java).
├── software                # Holds business logic in AWS lambda functions
│   ├── FunctionOne         # Sample Lambda function  
│   └── FunctionTwo         # Sample Lambda function
└── ...

Prerequisite

  • Make sure you have AWS CDK installed and configured with an aws account you want to use.
  • Ensure you have docker installed and is up and running locally.

Getting started

  • Change directory to where infrastructure code lives.
    cd infrastructure
  • Synthesize the cdk stack to emits the synthesized CloudFormation template. Set up will make sure to build and package the lambda functions residing in software directory. Build and packaging instruction for function resides in InfrastructureStack
    cdk synth
  • Deploy the CDK application
    cdk deploy

Useful commands

  • mvn package compile and run tests
  • cdk ls list all stacks in the app
  • cdk synth emits the synthesized CloudFormation template
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk docs open CDK documentation

Enjoy!

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

cdk-lambda-packaging-java's People

Contributors

dependabot[bot] avatar amazon-auto avatar jmhreif avatar pankajagrawal16 avatar

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.