serverless / github-action

:zap::octocat: A Github Action for deploying with the Serverless Framework
Apache License 2.0
662 stars 173 forks source link

Error: AWS provider credentials not found in Github Action #75

Closed grardov closed 1 year ago

grardov commented 1 year ago

I'm creating a new project for creating lambdas. I created a Github Action for deploying my lambdas to AWS, however, I'm getting this error:

Error:
AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://slss.io/aws-creds-setup>.

Locally is working fine, I can deploy my lambdas without problems.

This is my serverless.yml file.

service: functions
frameworkVersion: "3"

provider:
  name: aws
  runtime: nodejs14.x

# Lambdas functions
functions:
  hello:
    handler: src/functions/hello/index.handler
    events:
      - httpApi:
          path: /lambdas/hello
          method: get

# Plugins
plugins:
  - serverless-plugin-typescript
  - serverless-offline

And this is the Github Action that I'm trying to run.

name: Deploy Lambdas Staging

on:
  push:
    branches:
      - develop

jobs:
  deploy:
    name: deploy
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [16.x]
    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci
      - name: serverless deploy
        uses: serverless/github-action@v3.1
        with:
          args: -c "serverless plugin install --name serverless-plugin-typescript && serverless deploy"
          entrypoint: /bin/sh
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          SLS_DEBUG: 1

The secrets are defined in my Github repository. I'm not sure if a need to do something else.

grardov commented 1 year ago

I found the issue. In my case, I'm using two different environments for deploying my functions to AWS. The issue was that I need to set the environment that I'm using in the action, then, the action able to find the correct secret for the specific environment.

environment:
  name: Staging # this the name of my env in Github repository.

I'll close the issue.