why is this: ``` this.addOutputs({ "ApiEn...
# sst
s
why is this:
Copy code
this.addOutputs({
      "ApiEndpoint": "https://"+ api.restApi.restApiId + "-" + process.env.VPC_ENDPOINT + ".execute-api." + this.region + ".<http://amazonaws.com/|amazonaws.com/>" + this.stage
    });
resulting in more than 1 output?
Copy code
Outputs:
    apiApiEndpoint71625CD3: https://<rest-api-id>.<http://execute-api.us-east-1.amazonaws.com/stage/|execute-api.us-east-1.amazonaws.com/stage/>
    ApiEndpoint: https://<rest-api-id>-<my-vpc-endpoint>.<http://execute-api.us-east-1.amazonaws.com/stage|execute-api.us-east-1.amazonaws.com/stage>
I don't know what is creating
apiApiEndpoint71625CD3
my complete stack, which is creating a private REST API within a VPC:
Copy code
import * as iam from '@aws-cdk/aws-iam'
import * as sst from "@serverless-stack/resources";
import {EndpointType} from '@aws-cdk/aws-apigateway'
import {InterfaceVpcEndpoint} from '@aws-cdk/aws-ec2'

export default class ApiStack extends sst.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    // import existing VPC endpoint
    const endpointAPIGateway = InterfaceVpcEndpoint.fromInterfaceVpcEndpointAttributes(this,'vpcEndpoint',{
      port: 443,
      vpcEndpointId: process.env.VPC_ENDPOINT
    })

    // allow incoming traffic to a private API only from a specified VPC endpoint
    const apiResourcePolicy = new iam.PolicyDocument({
      statements: [
        new iam.PolicyStatement({
          effect: iam.Effect.DENY,
          principals: [new iam.AnyPrincipal()],
          actions: ['execute-api:Invoke'],
          resources: ['execute-api:/*/*/*'],
          conditions: {
            StringNotEquals: {
              "aws:sourceVpce": process.env.VPC_ENDPOINT
            }
          }
        }),
        new iam.PolicyStatement({
          principals: [new iam.AnyPrincipal()],
          actions: ['execute-api:Invoke'],
          resources: ['execute-api:/*/*/*']
        })
      ]
    })

    // create the REST API
    const api = new sst.ApiGatewayV1Api(this, 'api', {
      defaultFunctionProps: {
        srcPath: "src",
      },
      restApi: {
        policy: apiResourcePolicy,
        endpointConfiguration: {
            types: [EndpointType.PRIVATE], 
            vpcEndpoints: [endpointAPIGateway]
          }
        },
        routes: {
          "GET /companies/{companyId}/profiles/search":"functions/company.handler",
          "GET /companies/{companyId}/communities/{communityId}/profiles/search":"functions/community.handler"
        },
      })


    // show the private REST API endpoint 
    // https://{rest-api-id}-{vpce-id}.execute-api.{region}.<http://amazonaws.com/{stage}|amazonaws.com/{stage}>
    this.addOutputs({
      "ApiEndpoint": "https://"+ api.restApi.restApiId + "-" + process.env.VPC_ENDPOINT + ".execute-api." + this.region + ".<http://amazonaws.com/|amazonaws.com/>" + this.stage
    });
  }
}
t
if you remove it both outputs go away?
s
No, if I remove it, only the one I created goes away leaving the one I didn't intend to create
Copy code
Outputs:
    apiApiEndpoint71625CD3: https://<rest-api-id>.<http://execute-api.us-east-1.amazonaws.com/<stage>/|execute-api.us-east-1.amazonaws.com/<stage>/>
I suppose it's coming from the ApiGatewayV1Api construct 🤷
it's not a deal breaker or anything, just confused me
t
Yeah that's odd, cdk must be adding that output
s
Looks like the underlying RestApi CDK construct does this
s
I've had the same experience. These additional outputs appear quite often for me.
It's annoyance at best though.