how can you console.log construct properties in SS...
# help
s
how can you console.log construct properties in SST/CDK? I just get weird output like
${Token[TOKEN.1210]}
. is there some way to evaluate those? or, really, I’m just trying to figure out the output of
api.url
(
sst.Api
).
t
yeah that's always confusing - the values aren't available at synthesize-time and only resolved once shipped to AWS
s
yeah. I keep getting
dev-microservices-api-base | CREATE_FAILED | AWS::CloudFront::Distribution | ApiDist7600D0E0 | Resource handler returned message: "Invalid request provided: The parameter origin name cannot contain a colon. (Service: CloudFront, Status Code: 400, Request ID: e00470cc-dbd0-496f-adf0-df008aa3fea2, Extended Request ID: null)" (RequestToken: 7a0a5711-1460-1fa3-de3c-efbe92b7e986, HandlerErrorCode: InvalidRequest)
and I’m not sure what’s wrong with the URL origin I’m passing to CloudFront
I would think this would cover it:
Copy code
origin: new origins.HttpOrigin(
          this.restApi.url.replace('https://', '').replace(/:\d+$/, '')
        ),
t
If you do need to inspect the only thing you can do is add an output afaik
ah yeah you don't have access to that in code, this is a confusing thing in cdk
s
ohh.. duh. of course.. if it’s spitting out that token, of course my replace won’t work
well, shoot
trying this:
origin: new origins.HttpOrigin(this.restApi.httpApi.apiEndpoint),
nope, same issue
t
This is ugly but I think the only thing you can do is use sst.Script to modify it after it's created
@Frank any other ideas?
CDK needs to support some kind of declarative data transformations, like VTL on tokens
s
I’ll engage with AWS support about this. it’s clearly a CDK issue
I could also just set an alias for the HTTP API (like api-blah) and then I can just hardcode that reference.
new origins.HttpOrigin('<http://api-blah.site.net|api-blah.site.net>')
f
Regex won’t work, but some simple string operations on token values will be translated to CloudFormation intrinsic functions ie.
Fn::Sub
,
Fn::Split
, etc
This should work
this.restApi.url.replace('https://', '')
s
I had that
f
Is it possible to rewrite
.replace(/:\d+$/, '')
using
split
, replace, and then
join
?
s
this.restApi.url
is the issue. its value is
${Token[TOKEN.1210]}
f
Can you try
this.restApi.url.replace('https://', '')
without the
.replace(/:\d+$/, '')
part? Run
sst build
, and share the block in CFN template in
.build/cdk.out
. Let’s see if CDK translated that to intrinsic function
s
yeah, at first I just had the string replacement with https. it still yelled at me about a colon, so I figured it was the port #. but if that’s always :443, I can just not use regex. lemme do a build and check the template.. I’ll let you know
t
How can CDK translate that?
Is there a way to define those CFN functions inside CDK?
f
I know
${var}${foo}
will get translated intrinsic function
There is, CDK has this Fn class that u can use
s
"TargetOriginId": "devmicroservicesapibaseApiDistOrigin1694CA258",
Copy code
"DomainName": {
                "Fn::GetAtt": [
                  "RestApi135E9C73",
                  "ApiEndpoint"
                ]
              },
it ignored my
.replace()
t
The only way I can think to do this is to construct it from the declarative transformations that CFN supports: https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_core.Fn.html
there’s
Fn.split
.. maybe I can do something with that
heyyyy, this looks promising!
Copy code
"DomainName": {
  "Fn::Select": [
    1,
    {
      "Fn::Split": [
        ":",
        {
          "Fn::GetAtt": ["RestApi135E9C73", "ApiEndpoint"]
        }
      ]
    }
  ]
}
aww man. “Invalid request provided: The parameter origin name must be a domain name”. I’ll have to export this value to see what in the world it is
t
so much fun 🙃
s
oh yes, totally how I want to spend my day! 😝
this is typical for AWS, though, in my experience. try & retry the thing 20x until you figure it out.
oh duh.. stupid mistake. forgot the “//” part of the URL protocol
@Frank @thdxr WORKS! thanks so much for the idea to use
core.Fn
, I wouldn’t have thought of that. I appreciate your help, as always 😌
I keep forgetting we’re not working with “real” values in CDK
f
👍