skip to Main Content

Hi can anyone help me how to deploy serverless with specific stage, I have 1 app with 2 stage dev and prod. When deploy to dev its working fine and successfully deployed, but with prod stage always get below error:

Error:
UPDATE_FAILED: FilterOptionLambdaFunction (AWS::Lambda::Function)
Resource handler returned message: "Lambda function xxxxxxx-api-prod-xxxxxx could not be found" (RequestToken: ee621797-de45-aa3f-118b-8f512d4a5f62, HandlerErrorCode: NotFound)

I tried to comment all function and leave 1 function to test deploy, but received another error as below:

Error:
UPDATE_FAILED: EnterpriseLogAccessIamRole (AWS::IAM::Role)
Unable to retrieve Arn attribute for AWS::Logs::LogGroup, with error message Resource of type 'AWS::Logs::LogGroup' with identifier '{"/properties/LogGroupName":"/aws/lambda/xxxxx-api-prod-api"}' was not found.

Here is my serverless.yml:

org: xxxxxx
app: comeby-api
service: comeby-scheduler-api
frameworkVersion: "3"

custom:
  serverless-offline:
    noPrependStageInUrl: true
  
  myEnvironment:
    MESSAGE:
      prod: "This is production environment"
      staging: "This is staging environment"
      dev: "This is development environment"

useDotenv: true

provider:
  name: aws
  runtime: nodejs14.x
  region: ap-southeast-1
  stage: prod

functions:
  api:
    handler: handler.handler
    events:
      - httpApi: "*"

  # Alikhsan
  SyncAlikhsanSB2: 
  SyncAlikhsanAMT:
  SyncAlikhsanASG:  
  SyncAlikhsanIOI:  
  SyncAlikhsanJSB:  
  SyncAlikhsanSPY:
    
  # Sync Product
  Shopify:  
  SyncSenheng:
  SyncXilnix:
  Puma:
  
  # Anything
  FilterOption:
  AriadneMaps:
    handler: scheduler/update/AriadneMaps.handler
    description: "Update Ariadne Maps (to view report of total visitor of specific store) in Database"
    memorySize: 512
    timeout: 900
    events:
      - schedule:
          rate: cron(00 22 * * ? *)
          enabled: true
      - http:
          path: /cron/ariadne
          method: get
  SendEmailUpdateProduct:
  ReportPurchasing:
  UpdateProductPricePuma:
  UpdateFootFallCam:
  
plugins:
  # - serverless-dotenv-plugin
  - serverless-offline
  - serverless-offline-scheduler

enter image description here

2

Answers


  1. I am guessing from those UPDATE_FAILEDs, you are using the same serverless file for both dev and prod deployment. Based on this assumption, you may have to provide separate service names for both of your deployments. If you have deployed to the dev environment already with service name comeby-scheduler-api, the next deployment for prod stage with the same service name will try to override the previous deployment.

    In my case, I tackled this using 2 separate serverless configuration files (one for dev and the other for prod). For dev deployment, my config file serverless-dev.yml looks like the following.

    service: service-dev
    
    provider:
      name: aws
      role: arn:aws:iam::<aws-account-id>:role/<my-lambda-role-name>
      region: <region>
      runtime: python3.8
      environment:
        DB_HOST: <host>
        DB_PASSWORD: <pass>
        DB_PORT: <port>
        DB_DATABASE: <db_name>
        DB_USER: <db_user>
        
    plugins:
      - serverless-python-requirements
      - serverless-secrets-plugin
      - serverless-api-compression
    
    package:
      patterns:
        - '!venv/**'
        - '!__pycache__/**'
        - '!node_modules/**'
        - '!test/**'
    
    functions:
      Lambda1:
        handler: lambda_file_name.handler_function_name
        memorySize: 512
        timeout: 900
        events:
          - s3:
              bucket: <bucket_name_for_this_lambda_trigger>
              event: s3:ObjectCreated:*
              rules:
                - prefix: <filter_trigger_file_prefix>
                - suffix: <filter_trigger_file_suffix>
              existing: <true if an existing s3 bucket, false otherwise>
    
    

    Whereas for the prod, the serverless-prod.yml file is,

    service: service-prod
    
    provider:
      name: aws
      role: arn:aws:iam::<aws-account-id>:role/<my-lambda-role-name>
      region: <region>
      runtime: python3.8
    
    ... rest is similar
    
    

    My deployment commands for these separate stages are.

    sls deploy -s dev -c serverless-dev.yml
    sls deploy -s prod -c serverless-prod.yml
    
    Login or Signup to reply.
  2. This error also occured for me because I had previously setup another (unrelated) service with the same name and environment.

    Serverless tried to update the existing cloudformation template but failed with the above message because the previously created resource and updated resources were not related in any way.

    The solution for me was to find and delete the old cloud formation template (because I did not actually need it anymore) but an alternative would have been to change environment name

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search