[英]Use AWS sdk ruby with custom AWS endpoints.json
我在與 AWS 雲不同的雲上部署一些服務,但這會暴露與 AWS 兼容的端點。
我得到了一個 endpoints.json 文件,看起來像這樣
{
"partitions": [
{
"defaults": {
"hostname": "{service}.{region}.{dnsSuffix}",
"protocols": [
"https"
],
"signatureVersions": [
"v4"
]
},
"dnsSuffix": "outscale.com",
"partition": "osc",
"partitionName": "Outscale",
"regionRegex": "^(cloudgouv|us|eu|ap)\\-\\w+\\-\\d+$",
"regions": {
"eu-west-2": {
"description": "EU (Paris)"
},
[...]
},
"services": {
"ec2": {
"endpoints": {
"eu-west-2": {"hostname": "fcu.eu-west-2.outscale.com"},
[...]
}
},
我怎樣才能輕松地將它導入我的 AWS sdk v3? 在查看文檔時,似乎有一些非常相似的東西可用,但我不確定我是否理解如何從我的 ruby 代碼加載此配置
我知道我可以做這樣的事情
Aws.config.update(
region: 'cloudgouv-eu-west-1'
)
但我不確定如何導入整個配置(尤其是端點名稱等),以便底層 sdks 自動使用它們而無需更改太多代碼
我最終使用 AWS internal API 添加分區
# config/initializers/aws.rb
# Monkeypatch the list of AWS endpoints
new_partitions = JSON.parse(
File.read(
Rails.root.join('config', 'aws_endpoints_outscale.json')
)
)
Aws::Partitions.add(new_partitions)
Aws.config.update(
region: ENV['AWS_REGION'],
endpoint: 'outscale.com',
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.