rurri / serverless-resources-env

Serverlss framework plugin, which after a deploy, fetches cloudformation resource identifiers and sets them on AWS lambdas, and creates local ./.serverless-resources-env/.<region>_<stage>_<function-name> file
MIT License
20 stars 7 forks source link

Functions missing environment variables because they are not found in cloud Formation #11

Closed rob-gonz closed 6 years ago

rob-gonz commented 6 years ago

Exact error produced in the CLI Log

Serverless: [serverless-resources-env] WARNING: Could not find cloud formation resources for addPartner.Could not find: [List of resources missing]

Problem

If you have a stack that involves more then 100 resources (not hard to do) this plugin will fail to grab some of those resources when it makes the request to Amazon. It is using the describe-stack-resources command that is limited to the first 100 resources in the stack.

Code where the problem exists

index.js

 /**
   * Looks up the CF Resources for this stack from AWS
   * @returns {Promise.<String>}
   */
  fetchCFResources() {
    const stackName = this.getStackName();
    this.serverless.cli.log(`[serverless-resources-env] Looking up resources for CF Named: ${stackName}`);
    return Promise.promisify(this.cloudFormation.describeStackResources.bind(this.cloudFormation))({
      StackName: stackName,
    });
  }

Fix

Please update this to instead use the list-stack-resources function provided by AWS. By default it uses pagination. I believe there is an option to not paginate if that is easier.

I would totally update it and make a pull request but javascript is definitely not in my wheelhouse for now. Doesn't mean I'm not going to try, but I don't have all that much time to spend on it.

Appreciation

I really do appreciate that you took the time to make this plugin. It really allows me to create a very dynamic application and deploy it at whim without having to worry about all the resources new id's/keys. I would really like to see this fixed. This is the only fault I've seen so far.

Bribery

Says you're from the Long Beach, CA in your profile. I call the LBC home too. Fix and deploy and I'll buy you a beer! 🍺

rob-gonz commented 6 years ago

Suffering from the same problem?

There is a workaround to keep you going. The resources I was creating were all prefaced with 'Ld' now what that was doing was pushing them to the bottom of the list in the return of describeStackResources (It sorts alphabetically). A workaround is to make sure that any Resource or Function name you use that will be used as a variable elsewhere should start with the letter 'A'. Anything/Everything else should not. Hope this helps someone.

rob-gonz commented 6 years ago

Looks like @tloltman has something for this already: GitHub

I Implemented their changes manually in my node_modules and it works great. Thank you @tloltman .

rurri commented 6 years ago

Fix from @tloltman Was merged in, and version bumped in npm