Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 31 additions & 4 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
peerDeps: ['tailscale-lambda-extension'],
// description: undefined, /* The description is just a string that helps people understand the purpose of the package. */
devDeps: ['husky'], /* Build dependencies for this module. */
bundledDeps: ['@types/aws-lambda', '@aws-lambda-powertools/metrics', 'socks-proxy-agent'],
bundledDeps: ['@types/aws-lambda', '@aws-lambda-powertools/metrics', 'socks-proxy-agent', '@aws-sdk/client-lambda'],
publishToPypi: {
distName: 'tailscale_lambda_proxy',
module: 'tailscale_lambda_proxy',
Expand All @@ -56,10 +56,18 @@ project.gitignore.addPatterns('*.DS_Store');

project.bundler.addBundle('./src/lambda/tailscale-proxy/', {
platform: 'node',
target: 'node20',
target: 'node22',
sourcemap: true,
});
project.postCompileTask.exec('cp assets/lambda/tailscale-proxy/index.js lib/lambda/tailscale-proxy/index.js');
project.postCompileTask.exec('cp assets/lambda/tailscale-proxy/index.js lib/lambda/tailscale-proxy/index.js.map');

project.bundler.addBundle('./src/lambda/proxy-warmer/', {
platform: 'node',
target: 'node22',
sourcemap: true,
});
project.postCompileTask.exec('cp assets/lambda/proxy-warmer/index.js lib/lambda/proxy-warmer/index.js');
project.postCompileTask.exec('cp assets/lambda/proxy-warmer/index.js lib/lambda/proxy-warmer/index.js.map');

project.synth();
74 changes: 74 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export class MyStack extends cdk.Stack {
// }
// },
// debug: true, // Enable debug logging, show request + response, search for lines starting with "[tailscale-"
// warmer: { // Optional, enables a "warmer" Lambda to keep proxy connections open/warm (cold start is about 5-10 seconds)
// functionName: name("tailscale-proxy-warmer"),
// concurrentInvocations: 2,
// }
});

const caller = new NodejsFunction(this, "tailscale-caller", {
Expand Down Expand Up @@ -182,6 +186,16 @@ A Proxy Lambda error can be identified by the following headers in the response:
- `ts-error-name`: The error name.
- `ts-error-message`: The error message.

### Reducing Cold starts

Cold starts occur when your function first has to connect to the Tailscale network, which can take between 5-10 seconds
as mentioned in the [Tailscale Lambda Extension](https://github.com/rehanvdm/tailscale-lambda-extension?tab=readme-ov-file#limitations)
docs. Subsequent requests are much faster as the connection is reused.

Cold starts can be mitigated by configuring a "warmer" Lambda function that periodically invokes the Proxy Lambda. The
number of warm connections is determined by the `concurrentInvocations` property. This setup helps maintain a pool of
warm connections to the Tailscale network, reducing latency for subsequent requests.

### Code Examples

Refer to the [tailscale-lambda-proxy-example](https://github.com/rehanvdm/tailscale-lambda-proxy-example) repository
Expand Down
2 changes: 2 additions & 0 deletions npm-link-manual.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ npm run default
npm run bundle
npm run compile
cp assets/lambda/tailscale-proxy/index.js lib/lambda/tailscale-proxy/index.js
cp assets/lambda/proxy-warmer/index.js lib/lambda/proxy-warmer/index.js



# For this proxy package to be used in the -caller project
Expand Down
Loading