Microsoft Azure
クラウドプラットフォーム
Microsoft Azure
概要
Microsoft Azureは、Microsoftが提供する包括的なクラウドプラットフォームです。Windows、Office 365との優れた統合性を持ち、ハイブリッドクラウド、AI・機械学習サービスを強力にサポートしています。エンタープライズ市場でAWSに次ぐ第2位のシェアを持ち、既存のMicrosoft環境を持つ企業での採用が急速に拡大しています。
詳細
Azureは2010年にサービスを開始し、現在では60以上のリージョンで展開され、Microsoft製品との親和性により企業のデジタル変革を支援しています。2025年の最新機能として、Azure AI FoundryプラットフォームでのマルチエージェントオーケストレーションやModel Router、11,000以上のAIモデルへのアクセス、リアルタイムAI機能のWebRTC対応、SQL Server 2025でのベクターデータベース機能などが挙げられます。
主な特徴
- ハイブリッドクラウド: オンプレミスとクラウドの統合されたエクスペリエンス
- Office 365統合: Microsoft 365との緊密な連携
- Azure Active Directory: 包括的なID・アクセス管理
- AI・機械学習: Azure OpenAI、Cognitive Servicesなどの先進的なAIサービス
- DevOpsツール: Azure DevOpsによる統合された開発・運用環境
2025年の最新機能
- Azure AI Foundry: 11,000以上のモデルによる統一AIプラットフォーム
- Model Router: 最適なAIモデルを自動選択してコストと品質を最適化
- Realtime API with WebRTC: 低遅延音声ストリーミング
- o3-mini: 最新の推論モデル(2025年1月31日リリース)
- SQL Server 2025: ベクターデータベース機能付きでAIアプリケーション対応
メリット・デメリット
メリット
- Microsoft製品エコシステムとの優れた統合
- ハイブリッドクラウドソリューションの充実
- エンタープライズ向けの強力なセキュリティとコンプライアンス
- Active Directoryとの統合による統一的なID管理
- .NET開発者にとって最適化された環境
- 豊富なAI・機械学習サービス
- Azure Resource Managerによる一元的なリソース管理
デメリット
- 複雑な料金体系
- Microsoft環境以外では恩恵が少ない場合がある
- 学習コストが高い(特にAzure固有のサービス)
- Linux環境でのサポートがAWSより限定的
- 一部のサービスで可用性がAWSより低い
- ドキュメントの品質にばらつきがある
参考ページ
- Microsoft Azure公式サイト
- Azureドキュメント
- Azure料金計算ツール
- Azure Well-Architected Framework
- Azure無料アカウント
- Microsoft Learn
書き方の例
1. 基本セットアップとアカウント設定
# Azure CLIのインストール
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
# Azure CLIにログイン
az login
# サブスクリプション一覧の表示
az account list --output table
# 特定のサブスクリプションに設定
az account set --subscription "Your Subscription Name"
# 現在のアカウント情報確認
az account show
# リソースグループの作成
az group create \
--name myResourceGroup \
--location japaneast \
--tags Environment=Production Project=WebApp
# 利用可能なリージョン一覧
az account list-locations --output table
2. コンピュートサービス(VM、コンテナ)
# Azure Virtual Machine作成(Azure SDK for Python)
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.resource import ResourceManagementClient
# 認証設定
credential = DefaultAzureCredential()
subscription_id = "your-subscription-id"
# クライアント初期化
compute_client = ComputeManagementClient(credential, subscription_id)
network_client = NetworkManagementClient(credential, subscription_id)
resource_client = ResourceManagementClient(credential, subscription_id)
# リソースグループ作成
resource_group_params = {
'location': 'japaneast',
'tags': {
'Environment': 'Production',
'Project': 'WebApp'
}
}
resource_client.resource_groups.create_or_update(
'myResourceGroup',
resource_group_params
)
# 仮想ネットワークの作成
vnet_params = {
'location': 'japaneast',
'address_space': {
'address_prefixes': ['10.0.0.0/16']
},
'subnets': [
{
'name': 'default',
'address_prefix': '10.0.0.0/24'
}
]
}
vnet_result = network_client.virtual_networks.begin_create_or_update(
'myResourceGroup',
'myVNet',
vnet_params
).result()
# パブリックIPアドレスの作成
public_ip_params = {
'location': 'japaneast',
'public_ip_allocation_method': 'Static',
'dns_settings': {
'domain_name_label': 'myvm-dns-label'
}
}
public_ip_result = network_client.public_ip_addresses.begin_create_or_update(
'myResourceGroup',
'myPublicIP',
public_ip_params
).result()
# ネットワークインターフェースの作成
nic_params = {
'location': 'japaneast',
'ip_configurations': [
{
'name': 'myIPConfig',
'subnet': {
'id': vnet_result.subnets[0].id
},
'public_ip_address': {
'id': public_ip_result.id
}
}
]
}
nic_result = network_client.network_interfaces.begin_create_or_update(
'myResourceGroup',
'myNIC',
nic_params
).result()
# 仮想マシンの作成
vm_params = {
'location': 'japaneast',
'hardware_profile': {
'vm_size': 'Standard_B2s'
},
'storage_profile': {
'image_reference': {
'publisher': 'Canonical',
'offer': '0001-com-ubuntu-server-focal',
'sku': '20_04-lts-gen2',
'version': 'latest'
},
'os_disk': {
'name': 'myOSDisk',
'create_option': 'FromImage',
'managed_disk': {
'storage_account_type': 'Premium_LRS'
}
}
},
'os_profile': {
'computer_name': 'myVM',
'admin_username': 'azureuser',
'disable_password_authentication': True,
'linux_configuration': {
'ssh': {
'public_keys': [
{
'path': '/home/azureuser/.ssh/authorized_keys',
'key_data': 'ssh-rsa AAAAB3NzaC1yc2E...'
}
]
}
}
},
'network_profile': {
'network_interfaces': [
{
'id': nic_result.id
}
]
}
}
vm_result = compute_client.virtual_machines.begin_create_or_update(
'myResourceGroup',
'myVM',
vm_params
).result()
print(f"VM created: {vm_result.name}")
# Azure Container Instances デプロイ
apiVersion: 2019-12-01
location: japaneast
name: webapp-container-group
properties:
containers:
- name: web-app
properties:
image: nginx:latest
ports:
- port: 80
protocol: TCP
resources:
requests:
cpu: 1.0
memoryInGB: 1.5
environmentVariables:
- name: ENV
value: production
- name: DEBUG
secureValue: false
- name: sidecar-logging
properties:
image: fluent/fluent-bit:latest
resources:
requests:
cpu: 0.5
memoryInGB: 0.5
volumeMounts:
- name: log-volume
mountPath: /var/log
osType: Linux
restartPolicy: Always
ipAddress:
type: Public
ports:
- port: 80
protocol: TCP
volumes:
- name: log-volume
emptyDir: {}
tags:
Environment: Production
Application: WebApp
3. ストレージとデータベースサービス
# Azure Storage操作
from azure.storage.blob import BlobServiceClient
from azure.cosmos import CosmosClient, PartitionKey
import os
# Blob Storage操作
connection_string = "DefaultEndpointsProtocol=https;AccountName=mystorageaccount;AccountKey=..."
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
# コンテナー作成
container_name = "webapp-uploads"
blob_service_client.create_container(container_name, public_access='blob')
# ファイルアップロード
blob_client = blob_service_client.get_blob_client(
container=container_name,
blob="uploads/sample.txt"
)
with open("local-file.txt", "rb") as data:
blob_client.upload_blob(
data,
metadata={
'author': 'user123',
'purpose': 'demo'
},
tags={
'environment': 'production',
'department': 'engineering'
}
)
# Azure Cosmos DB操作
cosmos_client = CosmosClient(
url="https://mycosmosdb.documents.azure.com:443/",
credential="your-primary-key"
)
# データベース作成
database_name = 'WebAppDB'
database = cosmos_client.create_database_if_not_exists(id=database_name)
# コンテナー作成
container_name = 'users'
container = database.create_container_if_not_exists(
id=container_name,
partition_key=PartitionKey(path="/userId"),
offer_throughput=400
)
# ドキュメント挿入
user_doc = {
'id': 'user123',
'userId': 'user123',
'name': '田中太郎',
'email': '[email protected]',
'status': 'active',
'createdAt': '2025-01-01T00:00:00Z'
}
container.create_item(body=user_doc)
# ドキュメント読み取り
user = container.read_item(item='user123', partition_key='user123')
print(f"Retrieved user: {user['name']}")
# SQL Server Database作成
from azure.mgmt.sql import SqlManagementClient
sql_client = SqlManagementClient(credential, subscription_id)
# SQLサーバー作成
server_params = {
'location': 'japaneast',
'administrator_login': 'sqladmin',
'administrator_login_password': 'SecurePassword123!',
'version': '12.0'
}
server_result = sql_client.servers.begin_create_or_update(
'myResourceGroup',
'myserver',
server_params
).result()
# データベース作成
database_params = {
'location': 'japaneast',
'sku': {
'name': 'S1',
'tier': 'Standard'
},
'max_size_bytes': 268435456000 # 250GB
}
db_result = sql_client.databases.begin_create_or_update(
'myResourceGroup',
'myserver',
'webappdb',
database_params
).result()
4. ネットワーキングとセキュリティ
# Azure Key Vaultとセキュリティ設定
from azure.keyvault.secrets import SecretClient
from azure.mgmt.keyvault import KeyVaultManagementClient
from azure.mgmt.network import NetworkManagementClient
# Key Vault作成
keyvault_client = KeyVaultManagementClient(credential, subscription_id)
vault_params = {
'location': 'japaneast',
'properties': {
'sku': {
'family': 'A',
'name': 'standard'
},
'tenant_id': 'your-tenant-id',
'access_policies': [
{
'tenant_id': 'your-tenant-id',
'object_id': 'your-object-id',
'permissions': {
'secrets': ['get', 'list', 'set', 'delete'],
'keys': ['get', 'list', 'create', 'delete'],
'certificates': ['get', 'list', 'create', 'delete']
}
}
],
'enabled_for_disk_encryption': True,
'enabled_for_template_deployment': True
}
}
vault_result = keyvault_client.vaults.begin_create_or_update(
'myResourceGroup',
'mykeyvault',
vault_params
).result()
# Key Vaultシークレット操作
secret_client = SecretClient(
vault_url="https://mykeyvault.vault.azure.net/",
credential=credential
)
# シークレット設定
secret_client.set_secret("database-password", "SecurePassword123!")
secret_client.set_secret("api-key", "your-api-key-here")
# シークレット取得
retrieved_secret = secret_client.get_secret("database-password")
print(f"Secret value: {retrieved_secret.value}")
# ネットワークセキュリティグループ作成
nsg_params = {
'location': 'japaneast',
'security_rules': [
{
'name': 'AllowHTTP',
'protocol': 'Tcp',
'source_port_range': '*',
'destination_port_range': '80',
'source_address_prefix': '*',
'destination_address_prefix': '*',
'access': 'Allow',
'priority': 100,
'direction': 'Inbound'
},
{
'name': 'AllowHTTPS',
'protocol': 'Tcp',
'source_port_range': '*',
'destination_port_range': '443',
'source_address_prefix': '*',
'destination_address_prefix': '*',
'access': 'Allow',
'priority': 110,
'direction': 'Inbound'
},
{
'name': 'AllowSSH',
'protocol': 'Tcp',
'source_port_range': '*',
'destination_port_range': '22',
'source_address_prefix': '10.0.0.0/16',
'destination_address_prefix': '*',
'access': 'Allow',
'priority': 120,
'direction': 'Inbound'
}
]
}
nsg_result = network_client.network_security_groups.begin_create_or_update(
'myResourceGroup',
'myNSG',
nsg_params
).result()
5. サーバーレスとFunctions
# Azure Functions (Python)
import azure.functions as func
import logging
import json
import os
from azure.cosmos import CosmosClient
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
# リクエストボディの取得
try:
req_body = req.get_json()
name = req_body.get('name', 'World')
except ValueError:
name = req.params.get('name', 'World')
# Cosmos DBへの接続
cosmos_client = CosmosClient(
url=os.environ['COSMOS_DB_URL'],
credential=os.environ['COSMOS_DB_KEY']
)
database = cosmos_client.get_database_client('WebAppDB')
container = database.get_container_client('logs')
# ログ記録
log_entry = {
'id': func.uuid(),
'timestamp': func.utcnow().isoformat(),
'name': name,
'function_name': 'HttpTrigger'
}
container.create_item(body=log_entry)
return func.HttpResponse(
json.dumps({
'message': f'Hello, {name}!',
'timestamp': log_entry['timestamp']
}),
status_code=200,
headers={'Content-Type': 'application/json'}
)
# Logic Apps ワークフロー定義
logic_app_definition = {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"triggers": {
"manual": {
"type": "Request",
"kind": "Http",
"inputs": {
"schema": {
"type": "object",
"properties": {
"email": {"type": "string"},
"message": {"type": "string"}
}
}
}
}
},
"actions": {
"Send_email": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['outlook']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail",
"body": {
"To": "@triggerBody()['email']",
"Subject": "Automated Response",
"Body": "@triggerBody()['message']"
}
}
},
"Store_in_database": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['cosmosdb']['connectionId']"
}
},
"method": "post",
"path": "/dbs/WebAppDB/colls/notifications/docs",
"body": {
"id": "@guid()",
"email": "@triggerBody()['email']",
"message": "@triggerBody()['message']",
"timestamp": "@utcnow()"
}
},
"runAfter": {
"Send_email": ["Succeeded"]
}
}
}
}
6. 監視とDevOps統合
# Azure Monitor とアラート設定
from azure.mgmt.monitor import MonitorManagementClient
from azure.mgmt.web import WebSiteManagementClient
monitor_client = MonitorManagementClient(credential, subscription_id)
# Application Insights作成
from azure.mgmt.applicationinsights import ApplicationInsightsManagementClient
app_insights_client = ApplicationInsightsManagementClient(credential, subscription_id)
app_insights_params = {
'location': 'japaneast',
'kind': 'web',
'application_type': 'web',
'retention_in_days': 90,
'flow_type': 'Bluefield',
'request_source': 'rest'
}
app_insights_result = app_insights_client.components.create_or_update(
'myResourceGroup',
'myAppInsights',
app_insights_params
)
# メトリックアラート作成
alert_rule_params = {
'location': 'global',
'description': 'Alert when response time exceeds 5 seconds',
'severity': 2,
'enabled': True,
'scopes': ['/subscriptions/your-subscription-id/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/myWebApp'],
'evaluation_frequency': 'PT1M',
'window_size': 'PT5M',
'criteria': {
'odata.type': 'Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria',
'all_of': [
{
'name': 'High Response Time',
'metric_name': 'AverageResponseTime',
'metric_namespace': 'Microsoft.Web/sites',
'operator': 'GreaterThan',
'threshold': 5000,
'time_aggregation': 'Average'
}
]
},
'actions': [
{
'action_group_id': '/subscriptions/your-subscription-id/resourceGroups/myResourceGroup/providers/microsoft.insights/actionGroups/myActionGroup'
}
]
}
alert_result = monitor_client.metric_alerts.create_or_update(
'myResourceGroup',
'HighResponseTimeAlert',
alert_rule_params
)
# Azure DevOps Pipeline (azure-pipelines.yml)
trigger:
branches:
include:
- main
paths:
include:
- src/*
variables:
azureSubscription: 'MyAzureServiceConnection'
resourceGroupName: 'myResourceGroup'
webAppName: 'myWebApp'
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: 'Build stage'
jobs:
- job: Build
displayName: 'Build'
pool:
vmImage: $(vmImageName)
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
npm run test
displayName: 'npm install, build and test'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: 'Deploy stage'
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: 'Deploy'
environment: 'production'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
displayName: 'Azure Web App Deploy'
inputs:
azureSubscription: $(azureSubscription)
appType: 'webAppLinux'
appName: $(webAppName)
runtimeStack: 'NODE|18-lts'
package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
- task: AzureCLI@2
displayName: 'Post-deployment health check'
inputs:
azureSubscription: $(azureSubscription)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
# ヘルスチェック
response=$(curl -s -o /dev/null -w "%{http_code}" https://$(webAppName).azurewebsites.net/health)
if [ $response -eq 200 ]; then
echo "Deployment successful - Health check passed"
else
echo "Deployment failed - Health check failed with status $response"
exit 1
fi
Microsoft Azureは、Microsoftエコシステムとの強力な統合とエンタープライズ向けの包括的なソリューションを提供し、ハイブリッドクラウド環境での開発・運用を強力にサポートします。