Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dynamically defined resource names #46

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

maherio
Copy link
Contributor

@maherio maherio commented Dec 4, 2021

The Problem

Sometimes you want to dynamically define resources and environment variables in your serverless.yml file (i.e. using Fn::Join or Fn::Transform). This may get parsed as a python dict instead of a string, which breaks the current logic of this package (TypeError: str expected, not dict).

Proposed Solution

When parsing the serverless.yml file, transform certain properties (like the resource name) from a dict to a string. My solution simply strips invalid characters from the string, so you'd get a resource name like FnJoin-my-microservicetable. In my opinion it's not all that important what the transformed string becomes, since you'll want to pass that in as an environment variable anyway if your code needs to know it (see the unit tests I added for an example).

Disclaimer

I realize this could be a bit of a rabbit hole... there are all kinds of ways to define things in serverless/cloudformation/yaml, and those things aren't necessarily just the resource name (which is the only thing I've added here). That said, I don't think this hurts anything, and I'd rather the package supports some of these use cases than none at all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant