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

Customizing API REST Endpoint #13156

Closed
afern247 opened this issue Aug 26, 2023 · 3 comments
Closed

Customizing API REST Endpoint #13156

afern247 opened this issue Aug 26, 2023 · 3 comments
Labels
pending-triage Issue is pending triage question General question

Comments

@afern247
Copy link

afern247 commented Aug 26, 2023

Amplify CLI Version

12.3.0

Question

I need to create an endpoint with the following criteria:

  • Has caching on the server side
  • Uses domain
  • Can set api keys for customers and set usage plans
  • Has rate limit
  1. Is there a way to set this on amplify?
  2. I was looking at this but I'm not sure exactly how this fits in with the whole amplify ecosystem, is is different from amplify override api?

I need some high level guidance on this matter to create a scalable paid endpoint with the above criteria (which I can also use internally)

Note:

I tried using the cache for example while using the override method like the code below and it doesn't work:

import { AmplifyApiRestResourceStackTemplate, AmplifyProjectInfo } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyApiRestResourceStackTemplate, amplifyProjectInfo: AmplifyProjectInfo) {
    resources.cache = {
        enabled: true,
        ttl: Duration.seconds(3600),
    };
}
@afern247 afern247 added pending-triage Issue is pending triage question General question labels Aug 26, 2023
@ykethan
Copy link
Contributor

ykethan commented Aug 28, 2023

Hey @afern247, thank you for reaching out. I was able to utilize the following example to add rate limit, cache and API key.

resources.deploymentResource.stageDescription = {
    throttlingRateLimit: 1,
    cacheClusterEnabled: true,
    cacheTtlInSeconds: 3000,
    cacheClusterSize: "0.5",
  };

  resources.restApi.apiKeySourceType = "HEADER";
  resources.restApi.body.securityDefinitions = {
    ...resources.restApi.body.securityDefinitions,
    "use-api-key-in-header": {
      type: "apiKey",
      name: "x-api-key",
      in: "header",
      "x-amazon-apigateway-api-key-source": "HEADER",
    },
  };
  const custSecurityRules = [{ "use-api-key-in-header": [] }];
  Object.values(resources.restApi.body.paths).forEach((path: any) => {
    path.options.security = custSecurityRules;
    path["x-amazon-apigateway-any-method"].security = custSecurityRules;
  });

originally solution posted on rate limit and API key

additionally, the discord thread provides an example to setup usage plans using Amplify custom cfn resource.

Currently, the use cases are feature requests here: aws-amplify/amplify-category-api#938, aws-amplify/amplify-category-api#438. Please feel free in adding a thumbs up.

I was looking at this but I'm not sure exactly how this fits in with the whole amplify ecosystem, is is different from amplify override api?

To clarify, Amplify overrides enables extending functionality on resource created by Amplify CLI. Amplify custom resources provides functionality to create resource that are not supported as first-class categories in the Amplify ecosystem.

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Aug 28, 2023
@afern247
Copy link
Author

afern247 commented Sep 2, 2023

thanks for the info

@afern247 afern247 closed this as completed Sep 2, 2023
@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Sep 2, 2023
@github-actions
Copy link

github-actions bot commented Sep 2, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-triage Issue is pending triage question General question
Projects
None yet
Development

No branches or pull requests

2 participants