honerlaw / serverless-fargate-plugin

Serverless plugin to deploy fargate tasks to an ECS cluster.
44 stars 16 forks source link

Deployment fails if Serverless Application Name is Non Alphanumeric #16

Open ubaniabalogun opened 4 years ago

ubaniabalogun commented 4 years ago

Serverless deployment with the plugin fails when the serverless application name is non-alphanumeric. For example, the below serverless.yaml would not successfully deploy when the plugin is configured

service: example-service

plugins:
- serverless-fargate-plugin

custom:
  fargate:
    clusterName: Test

It will fail with error

 Error: The CloudFormation template is invalid: Template format error: Resource name example-serviceTestClust is non alphanumeric.

This is likely happening because the plugin is concatenating the raw service name with the clusterName property to form the namePrefix as linked below and serverless is attempting to use that namePrefix as the Resource name for the Cloudformation (CF) stack.

https://github.com/honerlaw/serverless-fargate-plugin/blob/e2bbdb370b583fff6cee8e9833dc28304c6afbbe/src/resources/cluster.ts#L15

CF however, requires alphanumeric names for Resource Names.

Raising this as an issue as non-alphanumeric service names above are valid in serverless.yaml files, and shouldn't be used to prefix strings that may be used as Resource Names in CF.

A couple of ways I can think of addressing this are: a) Auto substituting non-alphanumeric values in the namePrefix to make it alphanumeric before use (this could break existing deployments using the plugin) b) Introducing a usePrefix flag that defaults to true but can be set to false if a user doesn't want clusterName prefixed

If either of those options sounds appealing or you have alternative options you'd like to explore, please let me know and I'd be happy to take a swing at creating a PR for the fix

dazza-codes commented 4 years ago

:+1: and go further

jameswoodley commented 4 years ago

This has just bitten me too, all my services are {{basename}}-whateveritsdoing - so I always have hyphens in the service name

tezqa commented 3 years ago

Someone on board? I really need to get this improvement.

gwdp commented 3 years ago

Hey guys, please, check https://github.com/hybridless/serverless-ecs-plugin, will actively support you there :)