# Access ApiGatewayRestApi id as a variable

**URL:** <https://forum.serverless.com/t/access-apigatewayrestapi-id-as-a-variable/1913>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [May 23, 2017, 7:32pm UTC](https://forum.serverless.com/t/access-apigatewayrestapi-id-as-a-variable/1913 "2017-05-23T19:32:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dehuszar](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dehuszar/32/50_2.png) [@dehuszar](https://forum.serverless.com/u/dehuszar)\
**Post date:** [May 23, 2017, 7:32pm UTC](https://forum.serverless.com/t/access-apigatewayrestapi-id-as-a-variable/1913/1 "2017-05-23T19:32:35Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![cardoni](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/cardoni/32/629_2.png) [@cardoni](https://forum.serverless.com/u/cardoni)\
**Post date:** [May 23, 2017, 7:35pm UTC](https://forum.serverless.com/t/access-apigatewayrestapi-id-as-a-variable/1913/2 "2017-05-23T19:35:16Z")

</div>

+1 👍

I’ve got the same issue as well.

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [May 24, 2017, 12:36am UTC](https://forum.serverless.com/t/access-apigatewayrestapi-id-as-a-variable/1913/3 "2017-05-24T00:36:41Z")

</div>

You should be able to get the API Gateway ID using `Ref`. See [http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)

---

<div class="post-metadata">

**Author:** ![rowanu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowanu/32/75_2.png) [@rowanu](https://forum.serverless.com/u/rowanu)\
**Post date:** [May 26, 2017, 3:09am UTC](https://forum.serverless.com/t/access-apigatewayrestapi-id-as-a-variable/1913/4 "2017-05-26T03:09:21Z")

</div>

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](https://serverless.com/framework/docs/providers/aws/guide/variables#reference-cloudformation-outputs) is for CloudFormation Outputs (i.e. from other stacks).

---

<div class="post-metadata">

**Author:** ![ninoartificial](https://avatars.discourse-cdn.com/v4/letter/n/2acd7d/32.png) [@ninoartificial](https://forum.serverless.com/u/ninoartificial)\
**Post date:** [May 3, 2019, 8:21am UTC](https://forum.serverless.com/t/access-apigatewayrestapi-id-as-a-variable/1913/5 "2019-05-03T08:21:11Z")

</div>

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

Compare:  
GET - [https://chjpngb443.execute-api.eu-central-1.amazonaws.com/test/facebook/messages](https://chjpngb443.execute-api.eu-central-1.amazonaws.com/test/facebook/messages)  
wss://rs1ekw8ha0.execute-api.eu-central-1.amazonaws.com/test

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?

---

<div class="post-metadata">

**Author:** ![moro](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/moro/32/4303_2.png) [@moro](https://forum.serverless.com/u/moro)\
**Post date:** [May 3, 2019, 9:25am UTC](https://forum.serverless.com/t/access-apigatewayrestapi-id-as-a-variable/1913/6 "2019-05-03T09:25:58Z")

</div>

please take a look [Reference Websocket Api url in serverless.yml](http://forum.serverless.com/t/reference-websocket-api-url-in-serverless-yml/7829)

---

<div class="post-metadata">

**Author:** ![ninoartificial](https://avatars.discourse-cdn.com/v4/letter/n/2acd7d/32.png) [@ninoartificial](https://forum.serverless.com/u/ninoartificial)\
**Post date:** [May 3, 2019, 11:05am UTC](https://forum.serverless.com/t/access-apigatewayrestapi-id-as-a-variable/1913/7 "2019-05-03T11:05:42Z")

</div>

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

Ref: ‘WebsocketsApi’

will give you the id
