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

API Gateway: Custom API key value and API key export #3233

Closed
2 of 5 tasks
alexarb opened this issue Jul 8, 2019 · 3 comments Β· Fixed by #7714
Closed
2 of 5 tasks

API Gateway: Custom API key value and API key export #3233

alexarb opened this issue Jul 8, 2019 · 3 comments Β· Fixed by #7714
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md in-progress This issue is being actively worked on.

Comments

@alexarb
Copy link

alexarb commented Jul 8, 2019

  • I'm submitting a ...
    • πŸͺ² bug report
    • πŸš€ feature request
    • πŸ“š construct library gap
    • ☎️ security issue or vulnerability => Please see policy
    • ❓ support request => Please see note at the top of this template.

Please add possibility to add custom value and modification for API key in API Gateway.
This feature supported by CFN - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-apikey.html#cfn-apigateway-apikey-value

Also there is need to be able to import existing API keys. For example to be able to migrate to CDK from CFN or manually created resources. And cross-stack interactions.

@alexarb alexarb added the needs-triage This issue or PR still needs to be triaged. label Jul 8, 2019
@SomayaB SomayaB added feature-request A feature should be added or improved. @aws-cdk/aws-apigateway Related to Amazon API Gateway labels Oct 10, 2019
@SomayaB SomayaB assigned nija-at and unassigned eladb Oct 10, 2019
@SomayaB
Copy link
Contributor

SomayaB commented Oct 11, 2019

Hi @alexarb, thanks for submitting a feature request! We will look into this and someone will update this issue when there is movement.

@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Oct 11, 2019
@johnmarian
Copy link

This is my temporary fix that I'm using in the meantime (just to be able to read the value into CDK):

import { Construct, IResource as IResourceBase, Resource } from "@aws-cdk/core";
import {
  CfnApiKey,
  ResourceOptions,
  RestApi,
  IApiKey,
  ApiKey,
  ApiKeyProps
} from "@aws-cdk/aws-apigateway";

/**
 * API keys are alphanumeric string values that you distribute to
 * app developer customers to grant access to your API
 */
export interface IApiKeyWithValue extends IApiKey {
  /**
   * The API key value.
   * @attribute
   */
  readonly value: string | undefined;
}

/**
 * An API Gateway ApiKey with value prperty.
 *
 * An ApiKey can be distributed to API clients that are executing requests
 * for Method resources that require an Api Key.
 */
export class ApiKeyWithValue extends Resource implements IApiKeyWithValue {
  public readonly value: string | undefined;
  public readonly keyId: string;

  constructor(scope: Construct, id: string, props: ApiKeyProps = {}) {
    super(scope, id, {
      physicalName: props.apiKeyName
    });

    const resource = new CfnApiKey(this, "Resource", {
      customerId: props.customerId,
      description: props.description,
      enabled: props.enabled || true,
      generateDistinctId: props.generateDistinctId,
      name: this.physicalName,
      stageKeys: this.renderStageKeys(props.resources)
    });

    this.keyId = resource.ref;
    this.value = resource.value;
  }

  private renderStageKeys(
    resources: RestApi[] | undefined
  ): CfnApiKey.StageKeyProperty[] | undefined {
    if (!resources) {
      return undefined;
    }

    return resources.map((resource: RestApi) => {
      const restApi = resource;
      const restApiId = restApi.restApiId;
      const stageName = restApi.deploymentStage!.stageName.toString();
      return { restApiId, stageName };
    });
  }
}

@nija-at nija-at added effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md labels Feb 13, 2020
@diogo-ap-old
Copy link

Hi. Is there any update on this request? Having the ability to specify the API Key value is important for us, but it is not supported by CDK:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md in-progress This issue is being actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants