serverless-appsync-plugin icon indicating copy to clipboard operation
serverless-appsync-plugin copied to clipboard

Allow user to specify logical ID for the GraphQLApi resource

Open theburningmonk opened this issue 2 years ago • 3 comments

At the moment, the logical ID for the AWS::AppSync::GraphQLApi resource is generated based on the API name, it'll be great to have the option to specify the logical ID ourselves.

Otherwise, it makes it painfully hard to reference the API resource in some cases. For example, I include the stage name in the API name because we use temporary stacks for each developer, and for feature work, but all these stacks are deployed in the same dev account.

You can try to add ${self:provider.stage} in places where you need to reference the GraphQL API resource, but there are plenty of places where the Serverless framework doesn't transform these, e.g. when used in environment variables or stack outputs.

It'll be great to be able to do something like this:

myApi:
  name: myapi-${self:provider.stage}
  logicalId: MyGraphQLApi
  ...

theburningmonk avatar Feb 15 '22 15:02 theburningmonk

Are you using multiple APIs in the same stack, or passing the appSync configuration as an array (even with just one item)?

The logical ID should be GraphQlApi for single API configs (without prefix), when custom.appSync is an object. The Api name is only added in the case of multiple APIs (array of objects).

Obviously, changing that now will force the AWS::AppSync::GraphQLApi resource to be recreated. This might be a problem if you already went to production (It would also be the case with custom names, though).

Side note: In v2, variables should make this less painful.

We could do one of two things:

  • introduce a custom logicalID as you suggested
  • backport variables capabilities into v1

bboure avatar Feb 15 '22 17:02 bboure

V2's variables looks great, is it easy to backport to v1? and is it supported by Serverless framework v2?

theburningmonk avatar Feb 22 '22 13:02 theburningmonk

is it easy to backport to v1?

it should be easy enough.

and is it supported by Serverless framework v2?

I need to double-check that, but I think it is.

bboure avatar Feb 22 '22 13:02 bboure