Giter Site home page Giter Site logo

envek / aws-sam-typescript-layers-example Goto Github PK

View Code? Open in Web Editor NEW
232.0 7.0 53.0 191 KB

Example project for developing AWS Lambda functions on TypeScript with all goodies: local development, tests, debugging, shared layers (3rd party and your own), and deploy.

Home Page: https://evilmartians.com/chronicles/serverless-typescript-a-complete-setup-for-aws-sam-lambda

License: MIT License

Makefile 6.41% TypeScript 90.45% JavaScript 1.74% Procfile 1.40%
lambda typescript aws-sam aws-lambda-node aws-lambda-layer aws-sam-cli lambda-functions serverless

aws-sam-typescript-layers-example's People

Contributors

aclaghorn avatar damika-anupama avatar don-smith avatar envek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-sam-typescript-layers-example's Issues

Makefile errors out if types are defined in separate file.

I've been following your guide on evilmartians, but the build process errors out at:

echo "{\"extends\": \"./tsconfig.json\", \"include\": [\"${HANDLER}\"] }" > tsconfig-only-handler.json
npm run build -- --build tsconfig-only-handler.json

After looking into it, it appears that the new json file is not created at all and I'm unsure about how to get it to create.

Node: 16.13.1 (Also doesn't work on 14.x)
SAM CLI: 1.36.0

Error: CustomMakeBuilder:MakeBuild on a MacOS 12.1

Hey im getting this error, and i cant seem to be able to fix it.
i just downloaded the repo and tryed to compile but i get this error.

Building codeuri: /Users/xxx/www/homelytics/realocity runtime: nodejs14.x metadata: {'BuildMethod': 'makefile'} architecture: x86_64 functions: ['Index']
Running CustomMakeBuilder:CopySource
Running CustomMakeBuilder:MakeBuild
Current Artifacts Directory : /Users/xxx/www/homelytics/realocity/.aws-sam/build/Index

Build Failed
Error: CustomMakeBuilder:MakeBuild - Make Failed: make: *** No rule to make target `build-Index'. Stop.

Local emulator with shared dependencies from a yarn workspace (monorepo)

We are having difficulty setting up a local environment, running with sam local start-api which uses a shared dependency from our yarn workspace.

Steps

  1. I have updated the make file to use yarn and replaced any instance of prefix with cwd
  2. Added our local package, @claimsgate/core to the dependencies property in package.json

example.ts

  • ClaimsGatePermissions.Funnels.canEditPages.id is just a string literal value.
import "source-map-support/register";
import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
import { ClaimsGatePermissions } from "@claimsgate/core";
/**
 * A simple example includes a HTTP get method.
 */
export const exampleHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
  // All log statements are written to CloudWatch
  console.debug(ClaimsGatePermissions.Funnels.canEditPages.id);

  return {
    statusCode: 200,
    body: JSON.stringify({
      message: ClaimsGatePermissions.Funnels.canEditPages.id,
    }),
  };
};

The following error is thrown when invoking the function.

FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\Rayyan\\Desktop\\Work\\Media Advancements\\Projects\\claimsgate\\packages\\aws\\node_modules\\@claimsgate\\core\\node_modules\\@claimsgate\\core-types\\node_modules\\@firebase\\database-compat\\node_modules\\@firebase\\database\\dist\\node-esm\\src\\core\\AppCheckTokenProvider.d.ts'

Is there something we are missing here? Historically in other packages of ours, to use a local dependency from our monorepo, we have always been able to add it to package.json and just begin using its functionality. If there was an issue, it would only be during a deployment pipeline?

Any advice would be much appreciated!

Lambda layers for application shared code?

Hi,

I've found your repo while searching for typescript + lambda layers...
At first your approach was perfect, but then I noticed something your article confirmed: it looks like the lambda layers are useless because all the code is in your functions, isn't it?
Requiring the common library with the relative path makes them being compiled by typescript... which means being copied inside the function folder... so what's the meaning of using layers?? I expected to have only the function code and the layers in other folders (requiring them with /opt/nodejs/utils...)

Am i missing something??

Thanks a lot

Please add a license file

Hi everyone, thank you for a really neat solution that you have provided!

I am working on a project at the moment, and I want to leverage your solution.

Would it be possible to add a LICENSE file to the project? For example, I am always using MIT License for my projects.

This way I can make a proper attribution to your project and give you the credit that you deserve.

Thank you!

Error 'Refusing to install package with name "delete-test-01" under a package'

Hi Envek, first of all thank you for this amazing project. I think it is still relevant because the implementation of AWS 'sam build' with esbuild results in a huge ".js" file with all the dependencies embedded in it, that's why I searched for your project.

I cloned your repository, then I ran "npm install", then "sam.cmd build" (i am on windows 10). Then I received the error bellow:

$ sam.cmd build
Your template contains a resource with logical ID "ServerlessRestApi", which is a reserved logical ID in AWS SAM. It could result in unexpected behaviors and is not recommended.
Building layer 'RuntimeDependenciesLayer'
Running CustomMakeBuilder:CopySource
Running CustomMakeBuilder:MakeBuild
Current Artifacts Directory : C:/Users/bnegrao/perch/aws-sam-typescript-layers-example/.aws-sam/build/RuntimeDependenciesLayer
mkdir -p "C:/Users/bnegrao/perch/aws-sam-typescript-layers-example/.aws-sam/build/RuntimeDependenciesLayer/nodejs"
cp package.json package-lock.json "C:/Users/bnegrao/perch/aws-sam-typescript-layers-example/.aws-sam/build/RuntimeDependenciesLayer/nodejs/"
npm install --production --prefix "C:/Users/bnegrao/perch/aws-sam-typescript-layers-example/.aws-sam/build/RuntimeDependenciesLayer/nodejs/"

Build Failed
Error: CustomMakeBuilder:MakeBuild - Make Failed: npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "delete-test-01" under a package
npm ERR! also called "delete-test-01". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR!
npm ERR! For more information, see:
npm ERR!     <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\bnegrao\AppData\Roaming\npm-cache\_logs\2022-08-25T03_37_54_922Z-debug.log
make: *** [C:\Users\bnegrao\perch\aws-sam-typescript-layers-example\Makefile:23: build-RuntimeDependenciesLayer] Error 1

I am new to typescript and javascript, so I am sorry if that's a silly issue.

Regards,
bruno

RuntimeDependenciesLayer rebuilding on every API request

First of all, thank you @Envek and others for both the great writeup at https://evilmartians.com/chronicles/serverless-typescript-a-complete-setup-for-aws-sam-lambda and for this template repo.

This is my first time using AWS SAM in general, and it's been tricky with Typescript.

Problem

When running sam local start-api, every request I make to http://127.0.0.1:3000/ triggers a rebuild of the dependency layer.

Steps to reproduce

The first visit will build the image as expected.

When refreshing the browse, based on this comment, I would expect the image not to rebuild since no source code would have changed.

However, on each request, the image appears to be rebuilt with the following log line:

RuntimeDependenciesLayer is a local Layer in the template

The time it takes to rebuild this image makes it difficult to develop my frontend.

The workaround I have right now is to just point my frontend at my dev environment in AWS, but I'd prefer to be able to run both front & backend locally.

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.