Luke Wyman
07/06/2021, 9:51 PMError: There is already a Construct with name 'SingersApi' in SingersStack [dev-karaoke-singers]
in the following sst/cdk Stack class:
import { RemovalPolicy } from '@aws-cdk/core';
import * as sst from '@serverless-stack/resources';
export default class SingersStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props);
const singersTable = new sst.Table(this, "singers", {
fields: {
singer_id: sst.TableFieldType.STRING,
},
primaryIndex: { partitionKey: 'singer_id'},
dynamodbTable: {
removalPolicy: RemovalPolicy.DESTROY
}
});
const singersApi = new sst.Api(this, 'SingersApi', {
defaultFunctionProps: {
environment: {
singersTable: singersTable.dynamodbTable.tableName,
},
},
});
singersApi.addRoutes(this, {
'POST /karaoke/singers': 'src/services/singers/functions/KAR_SNG_create_singer.handler',
'GET /karaoke/singers/{singerId}': 'src/services/singers/functions/KAR_SNG_get_singer.handler',
'GET /karaoke/singers': 'src/services/singers/functions/KAR_SNG_get_all_singers.handler',
'PUT /karaoke/singers/{singerId}': 'src/services/singers/functions/KAR_SNG_update_singer.handler',
'DELETE /karaoke/singers/{singerId}': 'src/services/singers/functions/KAR_SNG_delete_singer.handler',
});
singersApi.attachPermissions([singersTable]);
this.addOutputs({
'SingersApi': {
value: singersApi.url,
exportName: scope.logicalPrefixedName('SingersApi'),
}
});
}
}
It seems having 'SingersApi' in both const singersApi = new sst.Api(this, 'SingersApi', {
and
this.addOutputs({
'SingersApi': {
value: singersApi.url,
exportName: scope.logicalPrefixedName('SingersApi'),
}
});
is a no-go. These seem like similar, yet different context meanings of the api parameter. The later is the Key and ExportName in CFN. But what is the same parameter in the sst.Api
constructor?Frank
Frank
SingersApiEndpoint
or SingersApiURL
, if that works for you.Frank
Luke Wyman
07/06/2021, 9:59 PMLuke Wyman
07/06/2021, 10:00 PMFrank
Luke Wyman
07/06/2021, 10:02 PMFrank
Frank