DEV Community

Cover image for Configure AWS Lambda source paths with OpenJS Architect
SHAWNHOSEA for Begin

Posted on • Updated on

Configure AWS Lambda source paths with OpenJS Architect

Architect originally relied on convention over configuration — meaning you could expect the placement of Lambda function handlers, to appear in default and deterministic locations. Recently, we introduced configurable file paths, which allow you to have more granular configurability over your Architect and Begin projects source code. This might be important for you because you have an existing project structure and conventions or you may need to point your Lambdas at generated build artifacts from something like TypeScript.

Configure source for get / in package.json

Define the application Infra as Code (IaC) in package.json under the arc key.

{
  "arc": {
    "app": "begin-app",
    "http": {
      "/": {
        "method": "get",
        "src": "path/to/code"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Configure source for a larger app in package.json

Define IaC for a GraphQL app.

{
  "arc": {
    "http": {
      "/": { "method": "get", "src": "path/to/code"},
      "/api": { "method": "post", "src": "path/to/apollo"}
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

This enables you to configure separate source paths for your code for each Lambda function. It is a good idea to separate your code into single responsibility functions. Less code per function means faster cold-starts and deployments. This also makes sharing code and using transpilers a breeze!

Top comments (0)