TypeScript, AWS SAM and Rollup.js

This time we are using Rollup instead of Webpack and it is super easy. Also it requires less configuration.

Before going further I suggest you read the other blog post which will explain the conventions behind the Rollup configuration.

Rollup Configuration

const defaultConfig = {
plugins: [
output: {
format: 'commonjs',
external: [
const { Resources } = CloudFormation.yamlParse(fs.readFileSync('template.yml'))const entries = Object.values(Resources)
.filter(resource => resource.Type == 'AWS::Serverless::Function')
.filter(resource => resource.Properties.Runtime.startsWith('nodejs'))
.map(resource => {
const file = resource.Properties.Handler.split('.')[0]
const prefix = resource.Properties.CodeUri.substr(8)
return Object.assign({}, defaultConfig, {
input: `${prefix}/${file}.ts`,
output: {
format: 'cjs',
dir: `.rollup/${prefix}`,
export default entries

AWS SAM Template

Type: 'AWS::Serverless::Function'
Handler: index.handler
Runtime: nodejs10.x
CodeUri: .rollup/packages/my-function


packages/my-function/index.ts → .rollup/packages/my-function...
created .rollup/packages/my-function in 283ms

When developing you would want to start it in watch mode with --watch. Then you can always use sam local invoke as normal.

I build stuff at Relatel A/S, vivid traveller and gear junkie.