概要
AWS CDK v2.235.0では、API Gateway HTTP APIとEventBridge PutEventsの統合がサポートされました。また、ECSでnoneログドライバーが利用可能になり、RDS ProxyではIAM認証のためのデフォルト認証スキームがサポートされました。CloudWatch SyntheticsではPlaywright 4.0/5.0およびsyn-nodejs-3.0ランタイムが追加されています。本リリースには複数の破壊的変更が含まれており、特にリファレンスインターフェースの導入による型変更に注意が必要です。
新機能
API Gateway V2 Integrations: HTTP APIとEventBridge PutEventsの統合 (#35766)
HTTP APIからEventBridgeのPutEvents APIを呼び出すためのL2インテグレーションが追加されました。これまで手動でIAMロールやパラメータマッピングを設定する必要がありましたが、新しいHttpEventBridgeIntegrationクラスにより簡単に設定できます。
使用例
import * as apigwv2 from 'aws-cdk-lib/aws-apigatewayv2';
import { HttpEventBridgeIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
import * as events from 'aws-cdk-lib/aws-events';
const bus = new events.EventBus(this, 'EventBus');
const api = new apigwv2.HttpApi(this, 'HttpApi');
// デフォルト設定でEventBridgeに統合
api.addRoutes({
path: '/default',
methods: [apigwv2.HttpMethod.POST],
integration: new HttpEventBridgeIntegration('DefaultIntegration', {
eventBus: bus, // ターゲットのEventBus
}),
});
// PutEventsサブタイプを明示的に指定
api.addRoutes({
path: '/put-events',
methods: [apigwv2.HttpMethod.POST],
integration: new HttpEventBridgeIntegration('PutEventsIntegration', {
eventBus: bus, // ターゲットのEventBus
subtype: apigwv2.HttpIntegrationSubtype.EVENTBRIDGE_PUT_EVENTS, // PutEventsサブタイプ
}),
});
HttpEventBridgeIntegrationProps
| プロパティ | 型 | 説明 |
|---|---|---|
eventBus | IEventBus | ターゲットのEventBus(必須) |
subtype | HttpIntegrationSubtype | 統合サブタイプ(オプション) |
invocationRole | IRole | カスタムIAMロール(省略時は自動作成) |
description | string | 統合の説明 |
timeout | Duration | タイムアウト設定 |
ECS: noneログドライバーのサポート (#35819)
ECSコンテナでDockerのnoneログドライバーが利用できるようになりました。OpenTelemetryなど外部でログ収集を行う場合に、コンテナレベルのstdout/stderrロギングを無効化できます。
使用例
import * as ecs from 'aws-cdk-lib/aws-ecs';
const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef');
taskDefinition.addContainer('AppContainer', {
image: ecs.ContainerImage.fromRegistry('alpine'),
// noneログドライバーを使用してコンテナログを無効化
logging: ecs.LogDriver.none(), // ログを出力しない
});
利用シーン
- OpenTelemetryなどの外部ログ収集ツールを使用している場合
- コンテナレベルのログが不要でコスト削減したい場合
- セキュリティ上の理由でstdout/stderrを無効化したい場合
IoT Actions (Alpha): HTTPアクションのメッセージバッチングサポート (#36642)
AWS IoT RulesのHTTPアクションでメッセージバッチングがサポートされました。複数のメッセージをまとめて送信することで、効率的なデータ転送が可能になります。
使用例
import * as iot from '@aws-cdk/aws-iot-alpha';
import * as actions from '@aws-cdk/aws-iot-actions-alpha';
const topicRule = new iot.TopicRule(this, 'TopicRule', {
sql: iot.IotSql.fromStringAsVer20160323(
"SELECT * FROM 'device/+/data'"
),
});
// バッチングを有効にしたHTTPアクション
topicRule.addAction(new actions.HttpAction('https://example.com/api/batch', {
// バッチ設定
batchConfig: {
maxBatchSize: 100, // バッチあたりの最大メッセージ数
maxBatchSizeInBytes: 1048576, // バッチあたりの最大サイズ(バイト)
batchTimeout: Duration.seconds(60), // バッチのタイムアウト時間
},
}));
BatchConfigプロパティ
| プロパティ | 型 | 説明 |
|---|---|---|
maxBatchSize | number | バッチあたりの最大メッセージ数 |
maxBatchSizeInBytes | number | バッチあたりの最大サイズ(バイト) |
batchTimeout | Duration | バッチのタイムアウト時間 |
注意: batchConfigを指定すると、enableBatchingは自動的に有効化されます。
RDS: DatabaseInstanceとDatabaseClusterにIOPSメトリクスを追加 (#35773)
RDSのモニタリング機能が強化され、インスタンスレベルとクラスターレベルのIOPSメトリクスが追加されました。
使用例
import * as rds from 'aws-cdk-lib/aws-rds';
import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';
// DatabaseInstanceのIOPSメトリクス
const instance = new rds.DatabaseInstance(this, 'Instance', {
engine: rds.DatabaseInstanceEngine.mysql({ version: rds.MysqlEngineVersion.VER_8_0 }),
vpc,
});
// Read IOPSメトリクス
const readIopsMetric = instance.metricReadIOPS({
period: Duration.minutes(5),
statistic: 'Average',
});
// Write IOPSメトリクス
const writeIopsMetric = instance.metricWriteIOPS({
period: Duration.minutes(5),
statistic: 'Average',
});
// アラームの作成
new cloudwatch.Alarm(this, 'HighReadIopsAlarm', {
metric: readIopsMetric,
threshold: 10000,
evaluationPeriods: 3,
comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
});
// DatabaseClusterのボリュームIOPSメトリクス
const cluster = new rds.DatabaseCluster(this, 'Cluster', {
engine: rds.DatabaseClusterEngine.auroraMysql({ version: rds.AuroraMysqlEngineVersion.VER_3_04_0 }),
vpc,
writer: rds.ClusterInstance.provisioned('Writer'),
});
// Volume Read IOPsメトリクス(Aurora用)
const volumeReadIopsMetric = cluster.metricVolumeReadIOPs({
period: Duration.minutes(5),
statistic: 'Average',
});
// Volume Write IOPsメトリクス(Aurora用)
const volumeWriteIopsMetric = cluster.metricVolumeWriteIOPs({
period: Duration.minutes(5),
statistic: 'Average',
});
新しいメトリクスメソッド
DatabaseInstance:
metricReadIOPS()- インスタンスのRead IOPSmetricWriteIOPS()- インスタンスのWrite IOPS
DatabaseCluster:
metricVolumeReadIOPs()- クラスターボリュームのRead IOPsmetricVolumeWriteIOPs()- クラスターボリュームのWrite IOPs
RDS: RDS Proxyでデフォルト認証スキームをサポート (#35635)
RDS Proxyでシークレットを必要としないIAM認証のためのデフォルト認証スキームがサポートされました。
使用例
import * as rds from 'aws-cdk-lib/aws-rds';
const cluster = new rds.DatabaseCluster(this, 'Cluster', {
engine: rds.DatabaseClusterEngine.auroraMysql({ version: rds.AuroraMysqlEngineVersion.VER_3_04_0 }),
vpc,
writer: rds.ClusterInstance.provisioned('Writer'),
});
// デフォルト認証スキームを使用したRDS Proxy
const proxy = new rds.DatabaseProxy(this, 'Proxy', {
proxyTarget: rds.ProxyTarget.fromCluster(cluster),
vpc,
// デフォルト認証スキーム(IAM認証用)
defaultAuthScheme: {
authScheme: rds.AuthScheme.SECRETS, // 認証スキームの種類
iamAuth: rds.IamAuth.REQUIRED, // IAM認証を必須にする
description: 'Default IAM authentication',
},
});
defaultAuthSchemeプロパティ
| プロパティ | 型 | 説明 |
|---|---|---|
authScheme | AuthScheme | 認証スキームの種類(SECRETS) |
iamAuth | IamAuth | IAM認証の要件(REQUIRED / DISABLED) |
description | string | 認証スキームの説明 |
これにより、シークレットを使用せずにIAM認証のみでRDS Proxyを構成できます。
Synthetics: syn-nodejs-3.0ランタイムを追加 (#36652)
CloudWatch Syntheticsに新しいsyn-nodejs-3.0ランタイムが追加されました。Node.js 20.xとマルチチェックブループリントをサポートします。
使用例
import * as synthetics from 'aws-cdk-lib/aws-synthetics';
const canary = new synthetics.Canary(this, 'MyCanary', {
schedule: synthetics.Schedule.rate(Duration.minutes(5)),
test: synthetics.Test.custom({
code: synthetics.Code.fromAsset('canary'),
handler: 'index.handler',
}),
// syn-nodejs-3.0ランタイムを使用
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_3_0, // Node.js 20.x、マルチチェック対応
});
Synthetics: Playwright 4.0/5.0ランタイムを追加 (#36590)
CloudWatch SyntheticsでPlaywright 4.0および5.0ランタイムがサポートされました。
使用例
import * as synthetics from 'aws-cdk-lib/aws-synthetics';
// Playwright 4.0ランタイム
const canaryPlaywright4 = new synthetics.Canary(this, 'PlaywrightCanary4', {
schedule: synthetics.Schedule.rate(Duration.minutes(5)),
test: synthetics.Test.custom({
code: synthetics.Code.fromAsset('canary'),
handler: 'index.handler',
}),
runtime: synthetics.Runtime.SYNTHETICS_PLAYWRIGHT_4_0, // Playwright 4.0
});
// Playwright 5.0ランタイム
const canaryPlaywright5 = new synthetics.Canary(this, 'PlaywrightCanary5', {
schedule: synthetics.Schedule.rate(Duration.minutes(5)),
test: synthetics.Test.custom({
code: synthetics.Code.fromAsset('canary'),
handler: 'index.handler',
}),
runtime: synthetics.Runtime.SYNTHETICS_PLAYWRIGHT_5_0, // Playwright 5.0
});
CloudFormationリソース定義の更新 (#36694)
L1コンストラクトがCloudFormationの最新リソース定義に更新されました。
バグ修正
Core: DetachedConstruct.nodeを非列挙プロパティに変更 (#36672)
NodejsFunctionなどのコンストラクトを使用した際に、メタデータ収集時にValidationError: The result of fromAwsManagedPolicyName can not be used in this APIという警告が表示される問題が修正されました。
問題の詳細
AWS CDK v2.224.0以降、DetachedConstructのnodeプロパティがオブジェクトプロパティの反復処理時(Object.keys()やfor...inループ)でアクセスされ、エラーが発生していました。
修正後の動作
import * as lambda from 'aws-cdk-lib/aws-lambda-nodejs';
// 修正後は警告なしでNodejsFunctionを使用可能
const fn = new lambda.NodejsFunction(this, 'MyFunction', {
entry: 'src/handler.ts',
});
Events: MatcherクラスがmergeEventPattern関数と互換性を持つように修正 (#36602)
MatchクラスをonEvent関数と組み合わせて使用した際にエラーが発生する問題が修正されました。
修正前の問題
// 修正前: S3バケットのonCloudTrailEventでMatchを使用するとエラー
bucket.onCloudTrailEvent('SpecificDirectoryEvents', {
target: new LambdaFunction(lambdaFunction),
eventPattern: {
detail: {
resources: {
ARN: Match.wildcard(`${bucket.bucketArn}/directoryA/*`) // エラー
}
}
},
});
修正後の動作
import * as events from 'aws-cdk-lib/aws-events';
import * as s3 from 'aws-cdk-lib/aws-s3';
const bucket = new s3.Bucket(this, 'MyBucket');
// 修正後: Matchクラスが正常に動作
bucket.onCloudTrailEvent('SpecificDirectoryEvents', {
target: new targets.LambdaFunction(lambdaFunction),
eventPattern: {
detail: {
resources: {
ARN: events.Match.wildcard(`${bucket.bucketArn}/directoryA/*`) // 正常動作
}
}
},
});
OpenSearch Service: クロスアカウント暗号化でKMS Key ARNを使用 (#36020)
OpenSearch DomainでクロスアカウントKMSキーを使用する際、Key IDではなくARNが使用されるように修正されました。
修正後の使用例
import * as opensearch from 'aws-cdk-lib/aws-opensearchservice';
import * as kms from 'aws-cdk-lib/aws-kms';
// クロスアカウントKMSキーをインポート
const crossAccountKey = kms.Key.fromKeyArn(
this,
'CrossAccountKey',
'arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012'
);
// クロスアカウントキーを使用したOpenSearchドメイン
const domain = new opensearch.Domain(this, 'Domain', {
version: opensearch.EngineVersion.OPENSEARCH_2_11,
encryptionAtRest: {
enabled: true,
kmsKey: crossAccountKey, // クロスアカウントキーが正常に動作
},
});
Step Functions: MapステートのmaxConcurrencyでJSONata式をサポート (#36462)
MapステートのmaxConcurrencyプロパティでJSONata式が使用できるようになりました。
使用例
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
const map = new sfn.Map(this, 'MapState', {
itemsPath: '$.items',
// JSONata式でmaxConcurrencyを動的に設定
maxConcurrencyExpression: '{% $states.input.concurrencyLimit %}', // 入力から動的に取得
});
map.itemProcessor(new sfn.Pass(this, 'ProcessItem'));
API Gateway V2: インポートしたHttpApiでapiEndpointエラーを修正 (#36623)
HttpApi.fromHttpApiAttributes()でインポートしたAPIでapiEndpointにアクセスした際にRuntimeError: apiEndpoint is not configured on the imported HttpApiエラーが発生する問題が修正されました。
破壊的変更
ECS: ManagedInstancesCapacityProviderでsecurityGroupsが必須に (#36685)
ManagedInstancesCapacityProviderPropsのsecurityGroupsプロパティが必須になりました。CloudFormationでは元々必須でしたが、CDKでは省略可能でした。この変更により、コンパイル時にエラーを検出できるようになります。
移行方法
import * as ecs from 'aws-cdk-lib/aws-ecs';
// 修正前(省略可能だった)
const capacityProvider = new ecs.ManagedInstancesCapacityProvider(this, 'CapacityProvider', {
cluster,
autoScalingGroup,
// securityGroupsが省略されていた場合、デプロイ時にエラー
});
// 修正後(必須)
const capacityProvider = new ecs.ManagedInstancesCapacityProvider(this, 'CapacityProvider', {
cluster,
autoScalingGroup,
securityGroups: [securityGroup], // 必須: 少なくとも1つのセキュリティグループを指定
});
リファレンスインターフェースの導入による型変更 (#36359)
L2リソースにリファレンスインターフェースが導入され、いくつかの型が変更されました。
| 変更箇所 | 変更前 | 変更後 |
|---|---|---|
JobQueue.computeEnvironments の computeEnvironment | IComputeEnvironment | IComputeEnvironmentRef |
BackupPlanRule.props の backupVault | IBackupVault | IBackupVaultRef |
ApiDestination.fromApiDestinationAttributes() の戻り値 | ApiDestination | IApiDestination |
EventDestination.bus | IEventBus | IEventBusRef |
FlowLogDestination.bind() と ICluster.executeCommandConfiguration の一部 | ILogGroup | ILogGroupRef |
Events: ApiDestination.fromApiDestinationAttributes()の戻り値型変更 (#36535)
ApiDestination.fromApiDestinationAttributes()の戻り値がApiDestinationからIApiDestinationに変更されました。また、EventDestination.busがIEventBusからIEventBusRefに変更されました。
Logs: FlowLogDestination.bind()の戻り値型変更 (#36566)
FlowLogDestination.bind()およびICluster.executeCommandConfiguration内のメンバーがILogGroupからILogGroupRefに変更されました。
IoT Actions (Alpha): enableBatchConfigのデフォルト値変更 (#36642)
enableBatchConfigプロパティがデフォルトで明示的に無効化されるようになりました。動作自体は変わりませんが、CloudFormationテンプレートに変更が生じます。
Alphaモジュール (2.235.0-alpha.0)
Bedrock AgentCore Alpha: デフォルトCognito User Poolの修正 (#36323)
AgentCore GatewayのデフォルトCognito User PoolがM2M(Machine-to-Machine)認証をサポートするように修正されました。
変更内容
- OAuth 2.0クライアント認証情報フローをサポート
- Cognito Resource Serverに
readとwriteスコープを追加 - OAuth2トークンエンドポイントアクセス用のCognito Domainを作成
userPool、userPoolClient、userPoolDomain、resourceServerプロパティを公開
使用例
import * as agentcore from '@aws-cdk/aws-bedrock-agentcore-alpha';
// デフォルトCognito認証を使用したGateway
const gateway = new agentcore.Gateway(this, 'Gateway', {
// デフォルトのCognito認証が自動的にM2M認証をサポート
});
// 公開されたCognitoリソースにアクセス
const userPool = gateway.userPool;
const userPoolClient = gateway.userPoolClient;
const userPoolDomain = gateway.userPoolDomain;
const resourceServer = gateway.resourceServer;
破壊的変更: 既存のGatewayスタックでデフォルトCognito認証を使用している場合、User Pool Clientが置き換えられ、新しいResource ServerとDomainリソースが追加されます。
spec2cdk: Alphaモジュールで自動生成グラントをサポート (#36206)
Alphaモジュールで自動生成されたグラントメソッドがサポートされるようになりました。
まとめ
AWS CDK v2.235.0では、API Gateway HTTP APIとEventBridgeの統合、ECSのnoneログドライバー、RDS Proxyのデフォルト認証スキームなど、重要な新機能が追加されました。
特に注目すべきは、リファレンスインターフェースの導入による型システムの改善です。これにより、L1リソースをL2コンストラクトに直接渡すことが可能になりましたが、既存コードで型変更の影響を受ける可能性があります。
ECSのManagedInstancesCapacityProviderPropsでsecurityGroupsが必須になった変更は、CloudFormationの実際の要件を反映しており、デプロイ時ではなくコンパイル時にエラーを検出できるようになります。
Syntheticsの新しいランタイム(syn-nodejs-3.0、Playwright 4.0/5.0)により、最新の環境でCanaryテストを実行できます。RDSのIOPSメトリクス追加により、データベースのパフォーマンス監視がより詳細に行えるようになりました。
破壊的変更が複数含まれているため、アップグレード前に影響範囲を確認することをお勧めします。