Access ApiGatewayRestApi id as a variable

I’m trying to dynamically assemble a resource arn for a policy in the Resources section of my serverless.yml file. I’m able to get all the things I need except for the ApiGatewayRestApi id. I’ve looked at assembling variables like ${cf:${self:service}-${self:provider.stage}.ApiGatewayRestApi} but get the following error returned to my terminal:

Invalid variable reference syntax for variable cf:<myAPIName>.ApiGatewayRestApi.
You can only reference env vars, options, & files. You
can check our docs for more info.

I’ve also tried ${self:resources.Resources.ApiGatewayRestApi}, ${self:resources.ApiGatewayRestApi}, and ${self:resources.Outputs.ApiGatewayRestApi} with similar results.

Is there a way to use this value as a variable?

1 Like

+1 :thumbsup:

I’ve got the same issue as well.

You should be able to get the API Gateway ID using Ref. See

1 Like

Is the resource you’re trying to reference in the same stack as where you’re referencing it? If so, use Ref (as per @buggy’s comment) - the ${cf:...} variable syntax is for CloudFormation Outputs (i.e. from other stacks).

1 Like

I have added a websocket api gateway and would like to get the endpoint of it just like the rest api endpoint.


Note that the rest api and websocket api have differing ids, chjpngb443 and rs1ekw8ha0 respectively.

I couldn’t find a suitable Ref variable for the websocket api id. Does anyone know how to get this property?

please take a look Reference Websocket Api url in serverless.yml

Thanks. I am sorry I wasn’t able to find that one. For reference:

Ref: ‘WebsocketsApi’

will give you the id