gpt4 book ai didi

amazon-web-services - 在cloudformation中输出api键值

转载 作者:行者123 更新时间:2023-12-04 02:42:46 26 4
gpt4 key购买 nike

我有一个输出变量的cloudformation模板。输出变量之一是

 ApiGKeyId:
Description: "Api Key Id"
Value: !Ref ApplicationApiGatewayApiKey

这将返回 API 网关 key 的 ID,而不是实际值。有没有办法获取该值?

最佳答案

根据以下线程,不支持属性“Value”~
https://github.com/awslabs/serverless-application-model/issues/206

第三方维护可用属性一目了然: https://theburningmonk.com/cloudformation-ref-and-getatt-cheatsheet/

经过一番研究,我觉得除了使用自定义资源调用 lambda 函数之外,没有其他方法可以检索 ApiKey 的值。这是我的示例代码。

#######################################################
##### Start of Custom functions #####
#######################################################
ValueFunc:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: >
var response = require('cfn-response');
var AWS = require('aws-sdk');

exports.handler = function(event, context) {
var apiKeyID = event.ResourceProperties.ApiKeyID;
var apigateway = new AWS.APIGateway();
var params = {
apiKey: apiKeyID,
includeValue: true
};

apigateway.getApiKey(params, function(err, ApiKeyData) {
if (err) {
console.log(err, err.stack); // an error occurred
var responseData = { "mykey" : "error reading ApiKey" };
response.send(event, context, response.SUCCESS, responseData);
} else {
console.log(ApiKeyData.value); // successful response
var responseData = { "mykey" : ApiKeyData.value };
response.send(event, context, response.SUCCESS, responseData);
}
});
};
Handler: index.handler
Runtime: nodejs8.10
Timeout: 30
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/${LambdaExecutionRole}"
GetApiKeyValue:
Type: Custom::LambdaCallout
Properties:
ServiceToken: !GetAtt ValueFunc.Arn
ApiKeyID: !Ref ApiKey

关于amazon-web-services - 在cloudformation中输出api键值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58548895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com