简体   繁体   中英

CDK: ecs with aws system manager

I try to get some parameter from AWS System Manager for ECS Fargate Containers, but I get some problems. My code is:

secret_value = ssm.StringParameter.from_secure_string_parameter_attributes(
                self,
                "/spark/ssh_pub",
                parameter_name="/spark/ssh_pub",
                version=1
            )

container_sp = fargate_task_definition_sp.add_container(
                "pod-spark-master",
                image=ecs.ContainerImage.from_registry(
                    "xxxxxxxx.dkr.ecr.eu-central-1.amazonaws.com/spark-master:ready-for-test-deployment"),
                health_check=health_check_sp,
                logging=log_config_sp,
                secrets={
                    "SPARK_PUB": ecs.Secret.from_ssm_parameter(secret_value)
                    }
            )

Then I get this error:

jsii.errors.JSIIError: There is already a Construct with name '--spark--ssh_pub' in Stack [sandbox]

has someone any idea?

There are few possibilities.

  1. CDK Bug
    CDK has too many issues. Similar error was reported https://github.com/aws/aws-cdk/issues/8603 . So it can be a CDK bug. In this case, all we can do is raise an issue in the Github and hope they will fix which may not happen soon with having 1000+ issues reported and open.

  2. There are actually a few CDK constructs (AWS resources) to which the same name have been given. Search through your stack "sandbox" and make sure no duplicate name will be created. If the same construct can be created more than once and the name can be the same.

There is already a Construct with name '--spark--ssh_pub' in Stack [sandbox].

Please also make sure this is actually what you need.

image=ecs.ContainerImage.from_registry(
    "xxxxxxxx.dkr.ecr.eu-central-1.amazonaws.com...

Apparently the docker image is in your ECR. Then from_ecr_repository should be the one to use. AWS documentations are confusing and sometime incorrect. The from_registry is not to pull the images from ECR but from the DockerHub, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM