aws-actions / setup-sam

Action to set up AWS SAM CLI and add it to the PATH
Apache License 2.0
151 stars 23 forks source link

sam package fails to include node_modules when --template-file is specified #57

Closed sharmmoh1983 closed 2 years ago

sharmmoh1983 commented 2 years ago

When i am trying to run sam deploy with --template-file using aws-actions/setup-sam@v1 node_modules are not getting deployed

Please suggest

hoffa commented 2 years ago

What version of SAM CLI are you using? What commands are you using to deploy? What (if any) errors are you experiencing?

sharmmoh1983 commented 2 years ago

As i mentioned above I am using following step in in my github actions

jobs:
  build-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
      - uses: aws-actions/setup-sam@v1

   # sam build 
   - run: sam build --use-container
    # sam deploy
    - run: sam deploy --template-file template-test.yaml .......

There are no errors showing github actions logs and sam build and deploy commands run fine But when i see code on lambda there are no node_modules but the source code do get updated

hoffa commented 2 years ago

Thanks for the context. A couple more questions:

  1. Did it work before, but suddenly stopped working?
  2. Would you able to share parts of the template that includes the function? This could help try to reproduce the issue.
  3. Are you using esbuild by any chance? If yes, I wonder if https://github.com/aws/aws-sam-cli/issues/3772 or https://github.com/aws/aws-sam-cli/issues/3707 are related.
sharmmoh1983 commented 2 years ago

@hoffa Thanks for your response Please find the following points

Did it work before, but suddenly stopped working? No it never worked using --template-file , it only works when I run sam deploy without custom template file

 # sam deploy
    - run: sam deploy .......

In this case node nodules gets deployed .

Would you able to share parts of the template that includes the function?

This is just standard SAM way of defining lambda

Function:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: lambda/service
      Handler: index.handler
      FunctionName : !Sub ${Environment}
      Runtime: nodejs12.x
      Timeout: 10
      VpcConfig:
        SecurityGroupIds:
          - !GetAtt GroupId
        SubnetIds: 
          - !Ref SubnetId
      MemorySize: 128
      Environment:
        Variables:
          WSDL_URI : !Ref URI
      Role: !GetAtt LambdaRole.Arn
      Events:
        SystemAPI:
          Type: Api
          Properties:
            RestApiId: !Ref RestApi
            Path: /Service
            Method: POST

Are you using esbuild by any chance? I am not sure but most likely no

hoffa commented 2 years ago

I was able to reproduce it locally:

sam init --name sam-app --runtime nodejs14.x --dependency-manager npm --app-template hello-world
cd sam-app
sam build

sam deploy --guided --template-file template.yaml  # No node_modules
sam deploy --template-file template.yaml  # Still no node_modules
sam deploy  # Now node_modules is there
hoffa commented 2 years ago

I'm unable to transfer to issue, so I've instead created one at https://github.com/aws/aws-sam-cli/issues/4203

I'll close this issue in favor of that one. Thanks a lot for reporting the issue! 🙏