SAM CLI- Using "sam build" - Build includes non required folders

0

How can you force 'sam build' commands to not include sub directories such as /node_modules and tests. These get added to each function and take an incredible amount of time to 'build' and 'deploy'. Am I missing a step to stop these folders being included? using SAM CLI v1.55.0

질문됨 2년 전2416회 조회
2개 답변
0

Have you tried .npmignore as mentioned on this Github thread - https://github.com/aws/serverless-application-model/issues/308 - "sam build command uses npm to package up the build folder (for nodejs projects), so you can use .npmignore to tell it which files should be excluded from the build"

profile pictureAWS
전문가
답변함 2년 전
0

I have found in my template.yaml file under each resource you can declare a CodeUri - it appears to only build files from this directory. This works well for my use case as I have a seperate lambda layer I use which holds all dependencies needed. I will now just structure my lambdas under seperate directories and share code where needed. Snippet of tamplate.yaml:

  listProvisioningTemplates:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: src/provisioning/listProvisioningTemplates/
      Handler: index.handler
      Layers:
        - !Ref awsCommandsLayer
      Runtime: nodejs16.x
      Architectures:
        - x86_64
      MemorySize: 128
      Timeout: 100
      Description: A Lambda function that returns a static string.
      Policies:
        # Give Lambda basic execution Permission to the helloFromLambda
        - AWSLambdaBasicExecutionRole
    #Metadata:
    #  BuildMethod: makefile

Folder Structure

AWS-SAM-DIR:
  -src:
    -provisioning:
      -listProvisioningTemplates:
        index.js
  -template.yaml
  
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠