Search code examples
amazon-web-servicesaws-lambdagitlab-ciaws-samaws-sam-cli

how to use AWS SAM on NodeJs Lambda by Gitlab-ci?


My gitlab-ci.yml:

build_aws_sam:
  image: python:3.11
  stage: build
  before_script:
    - pip3 install awscli --upgrade
    - pip3 install aws-sam-cli --upgrade
  script:
    - sam build --config-env "dev"

Error:

Building codeuri: /builds/xxxx-aws/xxxx-application/serverless/src/populateDynamo runtime: nodejs18.x metadata: {} architecture: x86_64 functions: ServerlessDynamoStack/PopulateDynamoFunction
package.json file not found. Continuing the build without dependencies.
Build Failed
Error: NodejsNpmBuilder:Resolver - Path resolution for runtime: nodejs18.x of binary: npm was not successful

I try add this in before_script but same error:

    - pip3 install nodejs-bin --upgrade
    - pip3 install npm --upgrade

I read AWS official documentation for aws-sam-cli and we need use Python image.


Solution

  • Solution work for me: - apt-get install nodejs -yq but after a curl on https://deb.nodesource.com/setup_18.x

    full gitlab-ci file:

    build_aws_sam:
      image: python:3.11
      stage: build
      before_script:
        - pip3 install awscli --upgrade
        - pip3 install aws-sam-cli --upgrade
        - apt-get update -y
        - curl -sL https://deb.nodesource.com/setup_18.x | bash
        - apt-get install nodejs -yq
      script:
        - sam build --config-env "dev"