Skip to content

Not working with serverless-offline #91

Open
@throrin19

Description

@throrin19

Hello,

It seems that this plugin doesn't work with serverless-offline, regardless of the order in which the plugins are called.

For example, when I run the package command, I get the parsing warning but then the $forEach are replaced, whereas when I run sls offline, I only get the parsing warning, without the $forEach modifications:

  • With sls package :
    > sls package
    Warning: Invalid configuration encountered
      at 'functions.companiesCreate.environment': unrecognized property '$forEach'
      at 'functions.companiesDelete.environment': unrecognized property '$forEach'
    
    Learn more about configuration validation here: http://slss.io/configuration-validation
    Packaging my-package for stage local (eu-west-1)
    ✔ Found and replaced 2 $forEach matches
    
  • With sls offline :
    > sls offline start --stage local --httpPort 8001 --lambdaPort 9001
    
    Warning: Invalid configuration encountered
      at 'functions.companiesCreate.environment': unrecognized property '$forEach'
      at 'functions.companiesDelete.environment': unrecognized property '$forEach'
    
    Learn more about configuration validation here: http://slss.io/configuration-validation
    Warning: No external modules needed
    
    Starting Offline at stage local (eu-west-1)
    
    Offline [http for lambda] listening on http://localhost:9001
    

I try to forEach on env variables on my lambdas but it's correctly available after package, but not in serverless-offline, only for $forEach part :

{
    functions : {
        companiesCreate : {
            handler              : 'src/handlers/companies-create-api.handler',
            maximumRetryAttempts : 0,
            events               : [
                {
                    http : {
                        method : 'post',
                        path   : '/companies',
                    },
                },
            ],
            environment : {
                $forEach : {
                    iterator : {
                        // simplify logic, only for debug purpose
                        ENV_ONE : process.env.ENV_ONE,
                        ENV_TWO : process.env.ENV_TWO,
                    }
                    template : {
                        '$forEach.key' : '$forEach.value',
                    },
                },
            },
        },
    },
    plugins : [
        'serverless-plugin-for-each',
        'serverless-esbuild',
        'serverless-prune-plugin',
        'serverless-analyze-bundle-plugin',
        // laisser en dernier
        'serverless-offline',
    ],
}

Is it possible to make it compatible with serverless-offline in order to keep the same logic between local development and deployment?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions