serverless / serverless

⚡ Serverless Framework – Effortlessly build apps that auto-scale, incur zero costs when idle, and require minimal maintenance using AWS Lambda and other managed cloud services.
https://serverless.com
MIT License
46.46k stars 5.72k forks source link

Support tagging per resource type #11722

Open ROSeaboyer opened 1 year ago

ROSeaboyer commented 1 year ago

Is there an existing issue for this?

Use case description

I have a large number of lambda functions in a few stacks, and a requirement to add tags to every resource being deployed. Right now, we're using the deprecated serverless-plugin-tag-cloud-watch-logs but are looking to replace that, preferably with native functionality as the approach used in that plugin causes throttling for us in some cases.

Proposed solution (optional)

The hierarchy would be provider.tags (if enabled) -> provider.log.tags -> provider.logs.<event>.tags/function[].logs.tags

I understand that there's been a lot of back and forth on this over the years, but I'm cautiously optimistic that this approach solves the long-standing concerns that people have around tagging.

medikoo commented 1 year ago

@ROSeaboyer per definition provider.stackTags are applied to all resources in the CloudFormation stack

ROSeaboyer commented 1 year ago

@medikoo Right, so that would allow us to avoid the need for adding provider.tags to the hierarchy. However, if I was to add tags to all of my log groups (and only my log groups), there's no way that I can find to do that short of making an extension resource for every independent log group.

If I were to remove the provider.tags references from the proposed solution, thoughts on the rest of it?

medikoo commented 1 year ago

@ROSeaboyer can you reclarify the use case then, as what you've explained as:

I have a large number of lambda functions in a few stacks and a requirement to add tags to every resource being deployed.

Can be addressed with provider.stackTags.

If that's not a solution, then I believe the use case was not explained well (or I have problems in understanding it)

ROSeaboyer commented 1 year ago

@medikoo I do have to add tags to each resource, but some of the tags I need to add are per resource type (ie all log groups), and some are individual to each individual resource, which is why I'm proposing a logs.tags attribute for the API Gateway definitions at the provider level and at the function level

medikoo commented 1 year ago

@ROSeaboyer thanks, that's clearer. This looks a rare use case that rather should be solved via external plugin. Still we can leave issue open, and if it gains significant interest we may consider taking that in.

spongenee commented 1 year ago

@medikoo a quick related question. Is there a way to (specifically) tag the Rest API, not the stages, other than using provider.stackTags that tags everything? I hope provider.tags tags the Rest API as well.

The concern is using 'stackTags' make many tagged resources irrelevant to the tag

medikoo commented 1 year ago

I hope provider.tags tags the Rest API as well.

@spongenee provider.tags are default tags for functions, and if I remember correctly they are also applied to REST API resources that are crated through http events on functions (still that might not be the case for the HTTP API, as that has been overlooked at implementation)

nbcchen commented 6 months ago

You can create a custom Serverless plugin and make a CloudWatchLogs:tagResource request