簡體   English   中英

如何將CDK映像資產部署到ECS集群

[英]How to deploy cdk image asset to ecs cluster

我正在嘗試將使用cdk創建的docker映像部署到ecs集群(ec2不是fargate)。

我已經在打字稿中嘗試了以下內容(當然有適當的導入)

    const vpc = new ec2.VpcNetwork(this, "MyVPC", { maxAZs: 3 });

    const cluster: ecs.Cluster = new ecs.Cluster(this, "ecs-cluster", {
      clusterName: "demo",
      vpc: vpc
    });

    cluster.addCapacity("MyEC2Capacity", {
      instanceType: new ec2.InstanceType("t2.micro"),
      desiredCapacity: 1
    });
    const image = new ecs.AssetImage(this, "image", {directory: "client"})

    const nameService = new ecs.LoadBalancedEc2Service (this, 'name-service', {
      cluster: cluster,
      desiredCount: 1,
      image: image,
      memoryLimitMiB: 128,
      containerPort: 3000
   });

但是,當我運行cdk diff ,出現以下錯誤

Stack cdkTest
The cdkTest stack uses assets, which are currently not accounted for in the diff output! See https://github.com/awslabs/aws-cdk/issues/395
IAM Statement Changes
Column width must be greater than 0.
npm verb lifecycle stack@0.1.0~cdk: unsafe-perm in lifecycle true
npm verb lifecycle stack@0.1.0~cdk: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/circleci/repo/stack/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
npm verb lifecycle stack@0.1.0~cdk: CWD: /home/circleci/repo/stack
npm info lifecycle stack@0.1.0~cdk: Failed to exec cdk script
npm verb stack Error: stack@0.1.0 cdk: `cdk "diff"`
npm verb stack Exit status 1
npm verb stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
npm verb stack     at EventEmitter.emit (events.js:197:13)
npm verb stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
npm verb stack     at ChildProcess.emit (events.js:197:13)
npm verb stack     at maybeClose (internal/child_process.js:978:16)
npm verb stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
npm verb pkgid stack@0.1.0
npm verb cwd /home/circleci/repo/stack
npm verb Linux 4.4.0-141-generic
npm verb argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "cdk" "diff" "--verbose"
npm verb node v11.9.0
npm verb npm  v6.5.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! stack@0.1.0 cdk: `cdk "diff"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the stack@0.1.0 cdk script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 1, true ]
npm timing npm Completed in 1578ms

Exited with code 1

是否有可能使cdk構建映像並部署到ecs?

如果可以,怎么辦? 我在Google,aws-cdk github存儲庫或aws-cdk文檔上都找不到任何示例。

任何幫助,不勝感激!

最終解決了該問題,因此可以在此處發布給其他人。

該問題是由我使用的CI引起的。 Node認為終端寬度為0(process.stdout.columns)。 這不是aws-cdk的問題,而是它用於構建更改和資源表的庫。

解決方法很簡單,只需將cdk的輸出通過管道傳遞給cat或類似的設備。 例如,我的CI任務從...更改

npm run cdk deploy

npm run cdk deploy | cat

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM