当用户创建新应用程序时,我还需要从AWS生成API密钥。我需要使用特定的使用计划(静态)来分配给每个新客户。我在params [:usage_plan_id] 中找回错误意外值,这会导致救援。我在这里缺少什么想法?
def create
@app = App.create(app_params)
begin
# ...
aws_client = Aws::APIGateway::Client.new(
region: "xxxxxxxxxxx",
access_key_id: AWS_ACCESS_KEY,
secret_access_key: AWS_ACCESS_SECRET
).create_api_key({
name: @app.name,
enabled: true,
generate_distinct_id: true,
usage_plan_id: "xxxxxx"
})
logger.debug aws_client.inspect
rescue => e
logger.error e.message
# ...
end
respond_with(@app)
end
答案 0 :(得分:1)
以下是需要发生的事情:
在aws配置文件中:
API_GATEWAY = Aws::APIGateway::Client.new(
region: "xxxxx",
access_key_id: "xxxxxxxxxxxxxxxx",
secret_access_key: "xxxxxxxxxxxxxx"
)
在控制器中:
aws_api_key = API_GATEWAY.create_api_key({
name: @app.name,
enabled: true,
generate_distinct_id: true,
stage_keys: [{
rest_api_id: "xxxxxxx",
stage_name: "xxxxxxxx"
}]
})
resp = API_GATEWAY.create_usage_plan_key({
usage_plan_id: "xxxxxx",
key_id: aws_api_key.id,
key_type: "API_KEY"
})