[英]AWS CDK Python Create App Load Balancer Listner with default action
[英]Cannot create CDK stack for AWS S3 Glacier in CDK app?
我決定使用AWS S3 Glacier進行數據歸檔。 所有 IaC 都是使用 CDK 應用程序 (TypeScript) 編寫的。 這就是我決定創建一個新的 CDK 應用程序並定義S3GlacierStack
的原因。 據我了解, StorageClass是最合適的方法。 如您所見,它支持 TypeScript。因此我決定創建一個簡單的 CDK 應用程序並嘗試使用AWS CDK 文檔中的代碼示例創建 S3 存儲桶。 不幸的是,我在運行cdk list
命令時遇到了以下錯誤: Error: Cannot use 'noncurrent' rules on a nonversioned bucket
。 我做錯什么了? 在 CDK 應用程序中使用 AWS S3 Glacier 靈活檢索存儲 class 的推薦方法是什么? 這是我的 CDK 應用程序的代碼。
cdk-app-1.ts
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { S3GlacierStack } from '../lib/s3-glacier-stack';
const app = new cdk.App();
new S3GlacierStack(app, 'S3GlacierStack', {});
s3-冰川-stack.ts
import * as cdk from 'aws-cdk-lib';
import * as s3 from "aws-cdk-lib/aws-s3";
import { Construct } from 'constructs';
export class S3GlacierStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const bucket = new s3.Bucket(this, 's3-glacier', {
lifecycleRules: [{
abortIncompleteMultipartUploadAfter: cdk.Duration.minutes(30),
enabled: false,
expiration: cdk.Duration.days(30),
expirationDate: new Date(),
expiredObjectDeleteMarker: false,
id: 's3-glacier',
noncurrentVersionExpiration: cdk.Duration.days(30),
// the properties below are optional
noncurrentVersionsToRetain: 123,
noncurrentVersionTransitions: [{
storageClass: s3.StorageClass.GLACIER,
transitionAfter: cdk.Duration.days(30),
// the properties below are optional
noncurrentVersionsToRetain: 123,
}],
objectSizeGreaterThan: 500,
prefix: 'prefix',
objectSizeLessThan: 10000,
transitions: [{
storageClass: s3.StorageClass.GLACIER,
// the properties below are optional
transitionAfter: cdk.Duration.days(30),
transitionDate: new Date(),
}],
}]
});
}
}
package.json
{
"name": "cdk-app-1",
"version": "0.1.0",
"bin": {
"cdk-app-1": "bin/cdk-app-1.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk"
},
"devDependencies": {
"@types/jest": "^27.5.2",
"@types/node": "10.17.27",
"@types/prettier": "2.6.0",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"aws-cdk": "2.50.0",
"ts-node": "^10.9.1",
"typescript": "~3.9.7"
},
"dependencies": {
"aws-cdk-lib": "2.50.0",
"constructs": "^10.0.0",
"source-map-support": "^0.5.21"
}
}
使用versioned: true
在 Bucket 上啟用 object 版本控制。
CDK 錯誤消息告訴您,如果未啟用存儲桶版本控制,您的非當前規則(如何處理以前的 object 版本)沒有意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.