简体   繁体   English

如何将CDK映像资产部署到ECS集群

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

I'm trying to deploy a docker image created with cdk to an ecs cluster (ec2 not fargate). 我正在尝试将使用cdk创建的docker映像部署到ecs集群(ec2不是fargate)。

I have tried the following in typescript (with appropriate imports of course) 我已经在打字稿中尝试了以下内容(当然有适当的导入)

    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
   });

However when I run cdk diff I get the following error 但是,当我运行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

Is it possible to get cdk to build the image and deploy to ecs? 是否有可能使cdk构建映像并部署到ecs?

If so how? 如果可以,怎么办? I couldn't find any examples either on google, on aws-cdk github repo, or on the aws-cdk docs. 我在Google,aws-cdk github存储库或aws-cdk文档上都找不到任何示例。

Any help much appreciated! 任何帮助,不胜感激!

Finally fixed the issue and so posting here for others. 最终解决了该问题,因此可以在此处发布给其他人。

The issue is caused by the CI I am using. 该问题是由我使用的CI引起的。 Node thinks that the terminal width is 0 (process.stdout.columns). Node认为终端宽度为0(process.stdout.columns)。 This is not an issue with aws-cdk but with the library it uses to construct the table of changes and resources. 这不是aws-cdk的问题,而是它用于构建更改和资源表的库。

A workaround is simple, simply pipe the output of the cdk to cat or similar. 解决方法很简单,只需将cdk的输出通过管道传递给cat或类似的设备。 So for example my CI task changes from... 例如,我的CI任务从...更改

npm run cdk deploy
to
npm run cdk deploy | cat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS cdk deploy --all 创建 ECS 服务失败 - AWS cdk deploy --all fails to create ECS service CDK 中的 ECS 角色无法访问 RoleArn - RoleArn not accessible for ECS Role in CDK 如何使用 CDK 将 AWS ECS (ApplicationLoadBalancedFargateService) 私有 IP 连接到 RDS 安全组 - How to Connect AWS ECS (ApplicationLoadBalancedFargateService) Private IP to RDS Security Group Using CDK AWS CDK 部署在 CodePipeline/CodeBuild - AWS CDK deploy in CodePipeline/CodeBuild 为什么这个 CDK 应用程序在 cdk deploy 中出现“内部故障”? - Why is this CDK app giving "Internal Failure" with cdk deploy? 如何使用 AWS CDK TYPESCRIPT 引用现有 VPC 来部署 Beanstalk 应用程序 - How to refer exsisting VPC to deploy Beanstalk app using AWS CDK TYPESCRIPT cfn 模板和管道都是使用 AWS CDK 创建的,如何使用 CodePipeline 部署 CloudFormation 堆栈? - How to deploy a CloudFormation stack using CodePipeline when both, the cfn template and the pipeline where created using the AWS CDK? 使用 AWS cdk 部署停靠的 .NET6 lambda 时如何自定义 docker 构建上下文? - How to customize docker build context when deploy a dockized .NET6 lambda using AWS cdk? 无法将 Nodejs 和 Typescript 部署到 AWS cdk + lambda - Cannot deploy Nodejs and Typescript to AWS cdk + lambda 使用 CDK 部署时似乎无法获取 SSM 参数 - Cannot seem to fetch SSM Parameter at deploy with CDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM