简体   繁体   中英

How can use an existing secret with an autoscaling group in cdk to enable ssh access

I have a cdk stack that creates an autoscale group

const key = new KeyPair(scope, 'KeyPair', {
   name: 'my-server',
   description: 'Key Pair created with CDK Deployment',
})
key.grantReadOnPublicKey

new autoscaling.AutoScalingGroup(scope, `${props.prefix}-api`, {
      vpc,
      role,
      securityGroup,
      instanceType: ec2.InstanceType.of(
        ec2.InstanceClass.T2,
        ec2.InstanceSize.MICRO
      ),
      machineImage: ami,
      userData,
      keyName: key.keyPairName,

      minCapacity: 1,
      maxCapacity: 1,
      associatePublicIpAddress: true,
      vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC },
    })
  }
}

This works well but I would like to use an existing secret to set key name but I am unable to find an example or documentation indicating how this can be achieved.

Just pass the name of the key

{
...
keyName: 'your_key_name'
...
}

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