Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(ec2.KeyPair): extraneous key [KeyFormat] is not permitted #28984

Closed
ajaykarpur opened this issue Feb 4, 2024 · 9 comments
Closed

(ec2.KeyPair): extraneous key [KeyFormat] is not permitted #28984

ajaykarpur opened this issue Feb 4, 2024 · 9 comments
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@ajaykarpur
Copy link

Describe the bug

I'm creating a new key pair like so:

        const keyPair = new ec2.KeyPair(scope, `${id}KeyPair`, {
            keyPairName: `${id}-keypair`,
        });

When I deploy the stack, I get this error:

The stack named MyStack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Properties validation failed for resource myKeyPair53D5213E with message:
#: extraneous key [KeyFormat] is not permitted

Expected Behavior

I'm not setting KeyFormat, so I expect it to default to PEM and deploy with no issues.

Current Behavior

The stack named MyStack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Properties validation failed for resource myKeyPair53D5213E with message:
#: extraneous key [KeyFormat] is not permitted

Reproduction Steps

        const keyPair = new ec2.KeyPair(scope, `${id}KeyPair`, {
            keyPairName: `${id}-keypair`,
        });

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.126.0 (build fb74c41)

Framework Version

No response

Node.js Version

v20.9.0

OS

macOS Ventura 13.5.2

Language

TypeScript

Language Version

No response

Other information

No response

@ajaykarpur ajaykarpur added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 4, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Feb 4, 2024
@msambol
Copy link
Contributor

msambol commented Feb 5, 2024

@ajaykarpur Are you updating a key pair by chance? I see UPDATE_ROLLBACK_COMPLETE. When I deploy a fresh one with the following code, it works:

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from 'aws-cdk-lib/aws-ec2'

export class CdkTestStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const someVar = 'test'

    const keyPair = new ec2.KeyPair(this, `${id}KeyPair`, {
      keyPairName: `${someVar}-keypair`,
    });
  }
}

@ajaykarpur
Copy link
Author

ajaykarpur commented Feb 5, 2024

Thanks for testing this! No, I'm not updating an existing key pair-- I'm trying to create a new one. Here's some additional context:

class UbuntuInstance extends ec2.Instance {
    constructor(scope: Construct, id: string, props: UbuntuInstanceProps) {
        const keyPair = new ec2.KeyPair(scope, `${id}KeyPair`, {
            keyPairName: `${id}-keypair`,
        });

        super(scope, id, {
            vpc: props.vpc,
            vpcSubnets: {
                subnetType: ec2.SubnetType.PUBLIC,
            },
            securityGroup: props.securityGroup,
            instanceType: new ec2.InstanceType("t3.large"),
            keyPair: keyPair,
            machineImage: ec2.MachineImage.genericLinux({
                ...

@msambol
Copy link
Contributor

msambol commented Feb 5, 2024

hmm, I can't reproduce. what happens if you don't specify keyPairName at all ?

@ajaykarpur
Copy link
Author

Just tried-- that didn't work either, unfortunately.

@msambol
Copy link
Contributor

msambol commented Feb 5, 2024

Can I see the CFN? Here's what mine is when I deploy:

  "CdkTestStackKeyPairFFFFFF": {
   "Type": "AWS::EC2::KeyPair",
   "Properties": {
    "KeyFormat": "pem",
    "KeyName": "CdkTestStack-keypair",
    "KeyType": "rsa"
   },

@ajaykarpur
Copy link
Author

Looks the same as mine:

 "testKeyPair53D5213E": {
  "Type": "AWS::EC2::KeyPair",
  "Properties": {
   "KeyFormat": "pem",
   "KeyName": "test-keypair",
   "KeyType": "rsa"
  },

I wonder if there's a CloudFormation bug in the region I'm using (us-gov-west-1)?

@msambol
Copy link
Contributor

msambol commented Feb 5, 2024

That could be it... can you try deploying in a different Region? If it works in that Region, could you reach out to AWS Support in the gov cloud account?

@pahud
Copy link
Contributor

pahud commented Feb 5, 2024

Yes I can't reproduce this in us-east-1 either. If it only happens at us-gov-west-1, please submit a ticket to AWS Support. Thank you.

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 5, 2024
Copy link

github-actions bot commented Feb 7, 2024

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants