Kanji
・Ingeniero Cloud / Freelance ・Nacido en 1993 ・De Ehime / Residente en Shibuya, Tokio ・5 años de experiencia en AWS Detalles del perfil
Índice
Script
AWS::SSM::Document
os
argparse
boto3
json
logging
time
datetime
The Python script in this article follows PEP8.
Syntax is checked with flake8 , and automatic formatting is done with black .
flake8
black
For code that needs to ignore checks due to processing requirements, # noqa is added.
# noqa
The maximum line length ( max-line-length ) is set to 200 characters.
max-line-length
The Python runtime version used for validation is 3.12.1.
ruamel.yaml
package-ssm-document.py
aws cloudformation package
import argparse import os from ruamel.yaml import YAML from ruamel.yaml.scalarstring import LiteralScalarString yaml = YAML() yaml.default_flow_style = False yaml.sort_keys = False def replace_script_with_inline_code(input_file, output_file): base_dir = os.path.dirname(input_file) with open(input_file, "r") as file: yaml_content = yaml.load(file) def process_main_steps(main_steps): for step in main_steps: if step.get("action") == "aws:executeScript" and "Script" in step["inputs"]: script_path = step["inputs"]["Script"] full_script_path = os.path.normpath(os.path.join(base_dir, script_path)) if os.path.exists(full_script_path): with open(full_script_path, "r") as script_file: script_content = script_file.read() step["inputs"]["Script"] = apply_literal_block_style(script_content) else: print(f"Warning: Script file not found at {full_script_path}") elif step.get("action") == "aws:loop" and "Steps" in step["inputs"]: process_main_steps(step["inputs"]["Steps"]) if "nextStep" in step: process_main_steps(step.get("nextStep", [])) def apply_literal_block_style(script_content): return LiteralScalarString(script_content) for resource in yaml_content.get("Resources", {}).values(): if resource.get("Type") == "AWS::SSM::Document": content = resource.get("Properties", {}).get("Content", {}) if "mainSteps" in content: process_main_steps(content["mainSteps"]) output_dir = os.path.dirname(output_file) if output_dir and not os.path.exists(output_dir): os.makedirs(output_dir) with open(output_file, "w") as file: yaml.dump(yaml_content, file) if __name__ == "__main__": parser = argparse.ArgumentParser(description="Transform parameter overrides in a YAML file.") parser.add_argument("--input-file", help="Path to the input YAML file.", default="template.original.yml") parser.add_argument("--output-file", help="Path to the output YAML file.", default="template.yml") args = parser.parse_args() replace_script_with_inline_code(args.input_file, args.output_file)
template.original.yml
template.yml
python package-ssm-document.py \ --input-file tests/template1.original.yml \ --output-file .alcache/template.yml
src/sample1.py
AWSTemplateFormatVersion: 2010-09-09 Description: template.yml Resources: TestRunbook: Type: AWS::SSM::Document Properties: Name: Sample-TestRunbook DocumentType: Automation DocumentFormat: YAML UpdateMethod: NewVersion Content: schemaVersion: '0.3' mainSteps: - name: SampleStep action: aws:executeScript isEnd: true inputs: Runtime: python3.11 Handler: main Script: src/sample1.py
AWSTemplateFormatVersion: 2010-09-09 Description: template.yml Resources: TestRunbook: Type: AWS::SSM::Document Properties: Name: Sample-TestRunbook DocumentType: Automation DocumentFormat: YAML UpdateMethod: NewVersion Content: schemaVersion: '0.3' mainSteps: - name: SampleStep action: aws:executeScript isEnd: true inputs: Runtime: python3.11 Handler: main Script: | def main(event, context): print("[sample1] Hello, World!") if __name__ == "__main__": main(None, None)
Real-time AI quant analysis of corporate earnings reports.
Entrene habilidades sociales con llamadas simuladas realistas, retroalimentación en 5 ejes, academia interactiva y fotos de perfil con IA.
Fotografíe recibos para un desglose instantáneo con IA. Conexión directa con LINE para liquidar gastos compartidos sin fricción.
Personajes de IA (Adivina, Mayordomo, Barman) moderan dinámicas y retos en tiempo real para animar cualquier reunión.
人工甘味料や添加物のNG除外と有効成分あたりの実質単価比較データベース。