How do I go about removing an Api that uses a cust...
# help
a
How do I go about removing an Api that uses a custom domain and is a source for the custom domain for another Api? I want to remove the parent Api without affecting the children.
t
what does source for the custom domain for another API mean
a
so there’s a v2 api where the custom domain is defined by specifying the url and the hosted zone and then there’s a v3 api that uses the apiGatewayDomainurl of the v2 api and just changes the path in the custom domain declaration to v3. I now want to remove the v2 api without impacting the v3 one, is that doable?
I think this would require playing with the api reference that I’m passing from the v2 api’s stack to the v3 api’s stack. Does that make sense?
t
what is a v3 api 😮
do you mean v1 and v2
I think I need to see a bit of the code, having a hard time understanding
a
sure, wait a minute.
this is my index.ts
Copy code
const appStackV2 = new AppStack(app, 'app-stack');

const appStackV3 = new AppStackV3(app, 'app-stack-v3', {
    appTable: appStackV2.appTable,
    v2Api: appStackV2.appApiV2,
    dwaarpaalIssuer: DWAARPAAL_ISSUER,
  });
this is an api’s v2 version from
AppStack
Copy code
this.appApiV2 = new sst.Api(this, 'app-api', {
      cors: {
        allowOrigins: ['*'],
        allowMethods: [CorsHttpMethod.GET, <http://CorsHttpMethod.POST|CorsHttpMethod.POST>, CorsHttpMethod.OPTIONS],
      },
      customDomain: {
        domainName: `${stageSubDomain}.${process.env.HOSTED_ZONE_NAME}`,
        hostedZone: hostedZone,
        path: process.env.API_VERSION,
      },
      defaultAuthorizationType: sst.ApiAuthorizationType.NONE,
      defaultFunctionProps: {
        environment: {
          stage: scope.stage,
          tableName: this.appTable.dynamodbTable.tableName,
        },
      },
      routes: {
        'GET /versions/supported': 'src/api/app/versions/supported.handler',
        'GET /test-numbers': 'src/api/app/test-auth/get-numbers.handler',
        'GET /test-numbers/{testPhoneNumber}/otp': 'src/api/app/test-auth/get-otp-for-number.handler',
        'POST /test-numbers': {
          function: {
            handler: 'src/api/app/test-auth/add-numbers.handler',
          },
          authorizer: adminApiAuthorizer,
          authorizationType: sst.ApiAuthorizationType.JWT,
        },
      },
    });
This is the same api’s v3 extension
Copy code
this.appApiV3 = new sst.Api(this, 'app-api-v3', {
      cors: {
        allowOrigins: ['*'],
        allowMethods: [CorsHttpMethod.GET, <http://CorsHttpMethod.POST|CorsHttpMethod.POST>, CorsHttpMethod.OPTIONS],
      },
      customDomain: {
        domainName: props?.v2Api.apiGatewayDomain,
        path: 'v3',
      },
      defaultAuthorizationType: sst.ApiAuthorizationType.NONE,
      defaultFunctionProps: {
        environment: {
          stage: scope.stage,
          tableName: props.appTable.dynamodbTable.tableName,
        },
      },
      routes: {
        'GET /versions/supported': 'src/api/app/versions/supported.handler',
        'GET /test-numbers': 'src/api/app/test-auth/get-numbers.handler',
        'GET /test-numbers/{testPhoneNumber}/otp': 'src/api/app/test-auth/get-otp-for-number.handler',
        'POST /test-numbers': {
          function: {
            handler: 'src/api/app/test-auth/add-numbers.handler',
          },
          authorizer: adminApiAuthorizer,
          authorizationType: sst.ApiAuthorizationType.JWT,
        },
      },
    });
Now, I need to remove the older version on the api without impacting the latter version, how do I do that?
t
can't you just switch it to
${stageSubDomain}.${process.env.HOSTED_ZONE_NAME}
in the second one
a
not sure, the last time I did, it gave me an error saying that the domain was already in use, I’ll still attempt it. But this brings up another question that how would I deal with referring constructs and dereference them.
t
what you can try is removing the api and then deploying just that stack
then updating the whole thing and deploying
this is a hard situation because it involves DNS which you should try as hard as possible not to need to take destructive actions on
a
yeah, I just love learning the hard way. 😅😂