忍者ブログ

Kazuhiro-Engine.

"カズヒロエンジン"って読みます。そのまま。 ITとか自転車とか雑記とか書きたいとか言ってたけど、もはや自転車メイン

AWS CloudFormationのIaCジェネレーターを使いたい(の覚書)



---
作りかけのPythonスクリプト
# 出力部分は、間違いなく修正が必要。
# 最悪、手動......
# 変数の命名規則ってあるんですか?
---
import json
import sys
import re
args = sys.argv
filename = args[1]
with open(filename, "r") as f:
    json_data = json.load(f)
    for list in json_data.values():
        for resourcedict in list:
            ResouceType = resourcedict["ResourceType"]
            ResourceIdentifier = resourcedict["ResourceIdentifier"]
            
            RType = ResouceType.split(":")[-1]
            LogicalResourceId = RType + "00"
            for value in ResourceIdentifier.values():
                LogicalResourceId = LogicalResourceId + value
            LogicalResourceId = re.sub(r'[^a-zA-Z0-9]', '', LogicalResourceId)
            
            json_datas  = f'{{"ResouceType": "{ResouceType}","LogicalResourceId": "{LogicalResourceId}","ResourceIdentifier": {ResourceIdentifier} }}'
            print(json_datas)
            
            with open('./resulet.json', 'a') as g:
                g.write(f"{json_datas},")

---
PR

コメント

プロフィール

Author:わた
新潟市に暮らすロードバイク(Cannondale)乗りの一人です。
年数回の、軽装での自転車旅行を楽しみにトレーニングしています。
早く走れたら、色んな場所に行ける!

他、自転車関係の情報は↓を参照。(ただし更新していない)
自転車関連の基本情報




Twitter

Twitterもやってます。



カレンダー

04 2024/05 06
S M T W T F S
1 2 3 4
5 6 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

カウンター

フリーエリア