How would I send the websocket API endpoint URL, a...
# sst
j
How would I send the websocket API endpoint URL, as environment variable or otherwise, to the lambda acting as server ?
t
This is a circular reference issue?
j
Yes. And the environment property isn't available/mutable after creating the Function, right ? If so, the circular reference would be easy to circumvent.
t
I typically store things in SSM and don't use environment variables. Then I have the lambda pull stuff during cold start
j
And since the server is required when creating the ApolloApi Construct, we cannot chain the operations : create API, create Function, link the two.
I understand but considering that it's doable with Api, since you can add the routes later, but not with ApolloApi, since the server is required at creation time, it just seems odd.
t
Yeah that's fair
I'm not familiar with the ApolloApi construct so not sure why it can't defer adding the function
I'll take a look in a second
j
I guess, the wrapper is so light (currently) that it just didn't seem like a relevant thing to do at the time.
t
It might be a good pattern for is to adopt to always provide functions to add things progressively and internally use them in the constructor if the props are specified
j
I think so. I feel like that could help solve circular references faster and easier.
t
Turns out you actually can mutate the environment afterward
Copy code
const apollo = new ApolloApi(...)
apollo.serverFunction.addEnvironment(...)
j
Ugh! I checked SST methods but not CDK methods... Thanks @thdxr
t
Are you using typescript? I found it by looking through autocomplete options
j
It had to be there somewhere...
t
Yeah I didn't know this existed either
j
Copy code
websocketApi.getFunction()?.addEnvironment()
apolloApi.getFunction()?.addEnvironment()
apollo.serverFunction
is only for
GET /
. So, I'll have to do
apolloApi.getFunction('GET /')?.addEnvironment()
and
apolloApi.getFunction('POST /')?.addEnvironment()
t
It uses the same function for both from what I can see
j
True. I could just skip the double call, assuming that that behavior never changes. Thanks 🙂