1

我是 typescript 和 nodejs 的新手,但需要对 typescript 代码进行一些修复。

我需要使用 Pulumi 运行 ECS 一次性任务,并且我有关于我们应该如何从 taskDefinition https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/awsx/ecs/运行任务的文档#EC2TaskDefinition-运行

但是没有文字描述,我无法理解我应该如何称呼这个run动作

public run: (params: RunTaskRequest) => Promise<awssdk.ECS.Types.RunTaskResponse>;

有一个关于如何使用 api-gateway 运行它的示例,但我不清楚如何将其run称为独立操作https://www.pulumi.com/docs/guides/crosswalk/aws/ecs/#running-即发即忘任务

感谢您对此的任何建议!

UPD:我拥有的更详细的代码块:

const kafkaTask = new awsx.ecs.FargateTaskDefinition("kafka1-task-efs", {
    vpc: vpcSelected,
    containers: {
        kafkaTask: {
            image: imageKafkaTaskEfs,
            logConfiguration: {
                logDriver: "awslogs",
                options: {
                    "awslogs-group": "ecs-kafka1",
                    "awslogs-region": "eu-central-1",
                    "awslogs-stream-prefix": "kafka1-task-efs"
                }
            },
            mountPoints: [
                {containerPath: "/mnt/kafka/data", sourceVolume: "kafka-data"},
                {containerPath: "/mnt/kafka/secrets", sourceVolume: "kafka-secrets"},
                {containerPath: "/mnt/zookeeper/log", sourceVolume: "zookeeper-log"},
                {containerPath: "/mnt/zookeeper/data", sourceVolume: "zookeeper-data"}
            ]
        }
    },
    volumes: [
        {name: "kafka-data", efsVolumeConfiguration: {rootDirectory: "/kafka-data", fileSystemId: fsKafka.id}},
        {
            name: "kafka-secrets",
            efsVolumeConfiguration: {rootDirectory: "/kafka-secrets", fileSystemId: fsKafka.id}
        },
        {
            name: "zookeeper-log",
            efsVolumeConfiguration: {rootDirectory: "/zookeeper-log", fileSystemId: fsKafka.id}
        },
        {
            name: "zookeeper-data",
            efsVolumeConfiguration: {rootDirectory: "/zookeeper-data", fileSystemId: fsKafka.id}
        }
    ]
});

kafkaTask.run({ cluster }).then(res => console.log(res)); 

UPD2:这是我最终遇到的错误:,但不确定它是否有用:

error: Running program '/pulumi/main-infrastructure' failed with an unhandled exception:
Error: Cannot call '.get' during update or preview.
To manipulate the value of this Output, use '.apply' instead.
    at Proxy.get (/pulumi/node_modules/@pulumi/pulumi/output.js:172:15)
    at FargateTaskDefinition.run (/pulumi/node_modules/@pulumi/ecs/taskDefinition.ts:226:39)
    at /pulumi/main-infrastructure/index.ts:127:15
    at Generator.next (<anonymous>)
    at fulfilled (/pulumi/main-infrastructure/index.ts:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
error: update failed
4

1 回答 1

0

我不确定您在哪里遇到问题,但是根据这些文档,您需要创建一个实例EC2TaskDefinition,因此您需要以下内容:

const task_def = new EC2TaskDefinition('', {}, {})

task_def.run({})
.then(res => console.log(res))

显然缺少一些参数,但我什至不确定您是否已经从您的问题中创建了一个类实例,如果是参数问题,那么请发表评论,我可以尝试扩展一下。

于 2020-07-18T12:55:34.073 回答