Skip to content

Adding a TypeScript CloudFront Function Example #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions typescript-cloudfront-functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
1 change: 1 addition & 0 deletions typescript-cloudfront-functions/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.12.1
27 changes: 27 additions & 0 deletions typescript-cloudfront-functions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Overview
This is a sample package to demonstrate how to use TypeScript with CloudFront Functions.

There is a `webpack.config.js` which bundles the TypeScript code and produces a single JavaScript file which can be uploaded as a CloudFront Function.
This JavaScript file exposes a global `handler` variable which points to the default export from your TypeScript file.

### Building this Package
To build the code and get a JavaScript file that can be uploaded to CloudFront, execute:
```shell
nvm use
npm install
npm run build
```

And then find your JavaScript file in the `dist/` directory.

### Adding a New Function
Just create a new TypeScript file in `src/` with a default export handler function that CloudFront Functions should run.
You can optionally add a unit test for this function by adding a file ending in `.test.ts` in the `tst/` directory.

And that's it! The Webpack config will automatically create a new application entrypoint for this TypeScript file and include a JavaScript version in the `dist/` directory.

### Testing
This package uses [Jest](https://jestjs.io/) for unit testing. To run tests, execute:
```shell
npm run test
```
Loading