Kanji
・Ingeniero Cloud / Freelance ・Nacido en 1993 ・De Ehime / Residente en Shibuya, Tokio ・5 años de experiencia en AWS Detalles del perfil
Índice
When using images in Mermaid, there are two main methods: “① Specify the image URL with the img tag” and “② Use an icon pack”. The following describes how to use the old AWS architecture icons.
img
Reference: How to change node shapes and specify images/icons in Mermaid flowchart #Beginner - Qiita
Use Mermaid’s img tag to directly specify the URL of an AWS icon.
flowchart TB subgraph ACCOUNT[AWS Account] subgraph GRP1[" "] ELB@{ img: "https://api.iconify.design/logos/aws-elb.svg", label: "ELB", pos: "b", w: 60, h: 60, constraint: "on" } end subgraph GRP2[" "] EC2@{ img: "https://api.iconify.design/logos/aws-ec2.svg", label: "EC2", pos: "b", w: 60, h: 60, constraint: "on" } end subgraph GRP3[" "] RDS@{ img: "https://api.iconify.design/logos/aws-rds.svg", label: "RDS", pos: "b", w: 60, h: 60, constraint: "on" } end ELB --- EC2 --- RDS end classDef vpc fill:none,color:#0a0,stroke:#0a0 class ACCOUNT vpc classDef group fill:none,stroke:none class GRP1,GRP2,GRP3 group
When rendered in Mermaid, it looks like this:
Another method is to use a Mermaid icon pack. This eliminates the need to specify a URL for each icon.
Reference: Registering icon pack in mermaid | Mermaid
flowchart TB subgraph ACCOUNT[AWS Account] subgraph GRP1[" "] ELB@{ icon: "logos:aws-elb", label: "ELB", pos: "b", h: 60} end subgraph GRP2[" "] EC2@{ icon: "logos:aws-ec2", label: "EC2", pos: "b", h: 60} end subgraph GRP3[" "] RDS@{ icon: "logos:aws-rds", label: "RDS", pos: "b", h: 60} end ELB --- EC2 --- RDS end classDef vpc fill:none,color:#0a0,stroke:#0a0 class ACCOUNT vpc classDef group fill:none,stroke:none class GRP1,GRP2,GRP3 group
However, this method cannot be used on SaaS platforms like Qiita or GitHub. To use an icon pack, you need to load a JSON file hosted on a CDN or server as shown below:
<script> mermaid.registerIconPacks([ { name: 'logos', loader: () => fetch('https://unpkg.com/@iconify-json/logos@1/icons.json').then((res) => res.json()), }, ]); mermaid.initialize({startOnLoad:true}); </script>
On this site, we use a custom icon pack created with the latest AWS architecture icons.
To use the latest AWS architecture icons, you need to create a custom Mermaid icon pack. This section explains how to create a Mermaid icon pack and use the latest AWS architecture icons.
First, download the latest AWS architecture icons from the following site. Click [Get Started] -> [Icon Package] to start the download.
AWS Simple Icons - AWS Architecture Center | AWS
The downloaded file is currently named Asset-Package_02072025.dee42cd0a6eaacc3da1ad9519579357fb546f803.zip . After extracting, you will see a folder structure like below. Use these files to create your Mermaid icon pack.
Asset-Package_02072025.dee42cd0a6eaacc3da1ad9519579357fb546f803.zip
Asset-Package_02072025.dee42cd0a6eaacc3da1ad9519579357fb546f803/ ├── Architecture-Group-Icons_02072025 │ ├── _32.png │ ├── _32.svg │ └── ... ├── Architecture-Service-Icons_02072025 │ ├── Arch_Cloud-Financial-Management │ ├── Arch_Compute │ └── ... ├── Category-Icons_02072025 │ ├── Arch-Category_16 │ ├── Arch-Category_32 │ └── ... └── Resource-Icons_02072025 ├── Res_Analytics └── Resource-Icons_02072025 ├── Res_Analytics ├── Res_Application-Integration └── ...
Next, save the following Python script in an appropriate directory (e.g., collect_mermaid_icons.py ). The script only uses standard libraries: re , os , json , and argparse .
collect_mermaid_icons.py
re
os
json
argparse
import re import argparse FOLDER_FILE_PATTERNS = { "Architecture-Group-Icons": "_32.svg", "Architecture-Service-Icons": "_48.svg", "Category-Icons": "_48.svg", "Resource-Icons": "_48.svg", } def get_icon_folders(icon_root): return [name for name in os.listdir(icon_root) if os.path.isdir(os.path.join(icon_root, name))] def extract_svg_size(svg_content): m = re.search(r'<svg[^>]*width=["\']?(\d+)["\']?[^>]*height=["\']?(\d+)["\']?', svg_content) if m: return int(m.group(1)), int(m.group(2)) return 0, 0 def collect_svg_icons(icon_root): icon_folders = get_icon_folders(icon_root) icons = {} for folder in icon_folders: print(f"Processing folder: {folder}") folder_path = os.path.join(icon_root, folder) if not os.path.isdir(folder_path): continue pattern = None for key, value in FOLDER_FILE_PATTERNS.items(): if folder.startswith(key): pattern = value break for root, dirs, files in os.walk(folder_path): for file in files: icon_name = os.path.splitext(file)[0] normalized_name = icon_name.replace(pattern.replace(".svg", "").replace(".png", ""), "") if pattern else icon_name file_path = os.path.join(root, file) if pattern: if not file.endswith(pattern): continue svg_content = "" try: with open(file_path, "r", encoding="utf-8") as svg_file: svg_content = svg_file.read() fill_colors = re.findall(r'fill=["\'](#[0-9a-fA-F]{3,6})["\']', svg_content, flags=re.IGNORECASE) if fill_colors: main_color = fill_colors[0] if fill_colors else None svg_content = re.sub(r'fill=["\']#fff(?:fff)?["\']', f'fill="{main_color}"', svg_content, flags=re.IGNORECASE) except Exception: svg_content = "" width, height = extract_svg_size(svg_content) icons[normalized_name] = {"body": svg_content, "width": width, "height": height} continue return icons def main(): parser.add_argument("--icon-root", type=str, help="Root directory of AWS architecture icons") parser.add_argument("--output-json", type=str, default="./icons.json", help="Path to output JSON file (default: ./icons.json)") parser.add_argument("--icon-list-txt", type=str, default="./icon_list.txt", help="Path to icon name list TXT file (default: ./icon_list.txt)") args = parser.parse_args() error_flags = False error_messages = [] if not args.icon_root or not os.path.isdir(args.icon_root): error_flags = True error_messages.append("The icon root directory is not specified correctly. Please use the --icon-root option.") if not args.output_json: error_flags = True error_messages.append("The path to the output JSON file is not specified. Please use the --output-json option.") if not args.icon_list_txt: error_flags = True error_messages.append("The path to the icon name list TXT file is not specified. Please use the --icon-list-txt option.") if error_flags: for msg in error_messages: print(f"Error: {msg}") return icons = collect_svg_icons(args.icon_root) output = {"prefix": "logos", "icons": icons} with open(args.output_json, "w", encoding="utf-8") as f: json.dump(output, f, ensure_ascii=False, indent=2) icon_names = sorted(icons.keys()) with open(args.icon_list_txt, "w", encoding="utf-8") as f: for name in icon_names: f.write(name + "\n") if __name__ == "__main__": main()
By running this script, you can collect SVG icons from the specified AWS architecture icon root directory and generate a JSON file in the Mermaid icon pack format.
To execute the script, run the following command from the terminal. This will collect icons from the specified directory and generate both icons.json and icon_list.txt files.
icons.json
icon_list.txt
python collect_mermaid_icons.py \ --icon-root /path/to/Asset-Package_02072025.dee42cd0a6eaacc3da1ad9519579357fb546f803 \ # Optional --output-json ./icons.json \ --icon-list-txt ./icon_list.txt
The generated icons.json file can be used as a Mermaid icon pack. Below is an example of the actual icon pack JSON generated by the script.
{ "prefix": "logos", "icons": { "Arch-Category_Storage": { "body": "<svg width=\"74px\" height=\"74px\" viewBox=\"0 0 74 74\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 74, "height": 74 }, "Arch_Amazon-EC2": { "body": "<svg width=\"64px\" height=\"64px\" viewBox=\"0 0 64 64\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 64, "height": 64 }, "Arch_Amazon-RDS": { "body": "<svg width=\"64px\" height=\"64px\" viewBox=\"0 0 64 64\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 64, "height": 64 }, "Arch_Elastic-Load-Balancing": { "body": "<svg width=\"64px\" height=\"64px\" viewBox=\"0 0 64 64\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 64, "height": 64 }, "Arch_Amazon-Simple-Storage-Service": { "body": "<svg width=\"64px\" height=\"64px\" viewBox=\"0 0 64 64\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 64, "height": 64 }, "Arch_AWS-Lambda": { "body": "<svg width=\"64px\" height=\"64px\" viewBox=\"0 0 64 64\" xmlns=\"http://www.w3.org/2000/svg\">...</svg>", "width": 64, "height": 64 } } }
El archivo icons.json completo (con más de 780 iconos SVG oficiales de AWS) se genera localmente en segundos ejecutando collect_mermaid_icons.py del Paso 2. Para optimizar la velocidad de carga de la página, arriba se muestra un extracto representativo de su estructura (EC2, RDS, ELB, S3 y Lambda).
Finally, load the Mermaid icon pack. If you want to load the JSON file from your server, add the following code to your HTML file:
<script> mermaid.registerIconPacks([ { name: 'logos', loader: () => fetch('./icons.json').then((res) => res.json()), }, ]); mermaid.initialize({ startOnLoad: true }); </script>
On this site, we implement it by writing the contents of the JSON file into the mermaid-icons-json element according to the page.
mermaid-icons-json
<script type="application/json" id="mermaid-icons-json"> </script> <script> mermaid.registerIconPacks([ { name: 'logos', loader: () => { const jsonText = document.getElementById('mermaid-icons-json').textContent; return Promise.resolve(JSON.parse(jsonText)); }, }, ]); mermaid.initialize({ startOnLoad: true }); </script>
To specify an icon pack, use the icon name after logos: . The available icon names in the pack you created are listed in the icon_list.txt file.
logos:
flowchart TB subgraph ACCOUNT[AWS Account] subgraph GRP1[" "] ELB@{ icon: "logos:Arch_Elastic-Load-Balancing", label: "ELB", pos: "b", w: 60, h: 60, constraint: "on" } end subgraph GRP2[" "] EC2@{ icon: "logos:Res_Amazon-EC2_Instance", label: "EC2", pos: "b", w: 60, h: 60, constraint: "on" } end subgraph GRP3[" "] RDS@{ icon: "logos:Arch_Amazon-RDS", label: "RDS", pos: "b", w: 60, h: 60, constraint: "on" } end ELB --- EC2 --- RDS end classDef vpc fill:none,color:#0a0,stroke:#0a0 class ACCOUNT vpc classDef group fill:none,stroke:none class GRP1,GRP2,GRP3 group
When displayed in Mermaid, it looks like this: As mentioned at the beginning, the ELB and RDS icons have different colors from the latest AWS architecture icons. This is because the color conversion did not work well when processing the AWS architecture icon SVG files.
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除外と有効成分あたりの実質単価比較データベース。