Node.js创建AWS AppConfig版本时如何获取ApplicationId等参数
获取AWS AppConfig接口所需参数的实操步骤
你可以通过AWS SDK for Node.js调用AppConfig的列表查询接口,基于你已有的信息匹配得到目标参数,具体操作如下:
1. 获取ApplicationId
你已持有Application名称,直接调用ListApplications接口,返回结果中匹配名称一致的条目即可拿到对应的Id字段,Node.js示例代码(基于AWS SDK v3):
import { AppConfigClient, ListApplicationsCommand } from "@aws-sdk/client-appconfig"; const appConfigClient = new AppConfigClient({ region: "你的AWS区域" }); const getApplicationId = async (appName) => { const command = new ListApplicationsCommand({}); const response = await appConfigClient.send(command); const targetApp = response.Items.find(app => app.Name === appName); return targetApp?.Id; }; // 调用示例,传入你持有的Application名称 const applicationId = await getApplicationId("你的Application名称");
注意:如果你的Application数量超过100个,需要处理NextToken分页逻辑才能遍历全量数据
2. 获取ConfigurationProfileId
拿到ApplicationId后,调用ListConfigurationProfiles接口,传入ApplicationId,再根据你持有的Configuration名称、环境关联信息过滤匹配,拿到对应Id字段,示例代码:
import { ListConfigurationProfilesCommand } from "@aws-sdk/client-appconfig"; const getConfigurationProfileId = async (applicationId, configName) => { const command = new ListConfigurationProfilesCommand({ ApplicationId: applicationId }); const response = await appConfigClient.send(command); const targetConfigProfile = response.Items.find(profile => profile.Name === configName); return targetConfigProfile?.Id; }; // 调用示例,传入上一步拿到的ApplicationId和你持有的Configuration名称 const configurationProfileId = await getConfigurationProfileId(applicationId, "你的Configuration名称");
额外说明
- 你持有的ClientId仅用于客户端拉取配置的
GetLatestConfiguration接口,本次获取两个ID的流程不需要用到该参数 - 拿到两个ID后,你就可以按照官方参数要求调用
CreateHostedConfigurationVersion接口完成配置版本创建
内容的提问来源于stack exchange,提问作者Володимир Васильківський
相关产品推荐
相关产品推荐

