我有这个问题。我想创建一个只能通过API密钥访问的API网关--这部分已经完成。现在我想将API密钥值存储在密钥管理器中。我可以在密钥管理器中存储硬编码的值,但不能存储API密钥的实际值。创建api密钥的代码为:
const key = api.addApiKey('ApiKey');并且我能够在secrets中存储一个硬编码的值,如下所示:
const secret = new secretsmanager.Secret(this, 'Secret', {
description: "Secret ",
secretName: "secret",
generateSecretString: {
secretStringTemplate: JSON.stringify({"api_key" : "some_value"}),
generateStringKey: "string_key",
}
});如何存储api密钥而不是硬编码值?
发布于 2021-02-11 00:20:41
我不认为有一种方法可以在没有自定义资源的情况下提取api键值。
但反过来也很容易做到这一点。我们首先需要生成密钥,并使用该值来创建api密钥。
const secret = new secretsmanager.Secret(this, 'Secret', {
generateSecretString: {
generateStringKey: 'api_key',
secretStringTemplate: JSON.stringify({ username: 'web_user' }),
excludeCharacters: ' %+~`#$&*()|[]{}:;<>?!\'/@"\\',
},
});
this.restApi.addApiKey('ApiKey', {
apiKeyName: `web-app-key`,
value: secret.secretValueFromJson('api_key').toString(),
});https://stackoverflow.com/questions/66135920
复制相似问题