Should we override the resource name when making it linkable because the original name is not suitable or contains illegal characters?
mario-shang opened this issue · comments
This is my use case:
- I want to use the existing topic here, but the original name is like "xxx-xxx," so building here will cause an error.
- Although I want to create a new topic in the dev stage and use the existing topic in the prod stage, but the generated name is different, which makes it unusable.
export async function getExistsTopic(topicName: string): Promise<aws.sns.Topic | undefined> {
const res = await aws.sns.getTopic({ name: topicName })
if (!res.id || !res.name) {
console.warn(`The topic ${topicName} doesn't exists.`);
return
}
const existsTopic = aws.sns.Topic.get(res.name, res.id);
// build the resource param will cause error
// sst.Link.makeLinkable(aws.sns.Topic, function () {
// return {
// properties: {
// arn: this.arn,
// },
// };
// })
sst.Link.AWS.makeLinkable(aws.sns.Topic, function () {
return [
{
actions: ["sns:*"],
resources: [this.arn],
},
];
});
return existsTopic;
}
ion/pkg/platform/src/components/link.ts
Lines 46 to 59 in 05e099d
I changed to using the Pulumi topic construct with the id in the options to avoid using the original name, like this:
export async function getExistsTopic(originTopicName: string): Promise<aws.sns.Topic | undefined> {
const res = await aws.sns.getTopic({ name: originTopicName });
if (!res.id) {
console.warn(`The topic ${originTopicName} doesn't exists.`);
return;
}
const topic = new aws.sns.Topic(TopicName, undefined, {
id: res.id,
});
sst.Link.makeLinkable(aws.sns.Topic, function () {
return {
properties: {
arn: this.arn,
},
};
});
sst.Link.AWS.makeLinkable(aws.sns.Topic, function () {
return [
{
actions: ["sns:*"],
resources: [this.arn],
},
];
});
return topic;
}