question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(apigateway): support deployment salting for imported RestApi

See original GitHub issue

If the RestApi is define by RestApi.fromRestApiAttributes(), any deployment will not add salt to the deployment resource.

Reproduction Steps

This is my code.

const api = RestApi.fromRestApiAttributes(this, 'ImportedApi', {
      restApiId: XXX,
      rootResourceId: XXX,
    });

    const allResources = api.root.addResource('cdk');

    allResources.addCorsPreflight({ allowOrigins: Cors.ALL_ORIGINS });

    const method = allResources.addMethod('PUT', ifn, {
      methodResponses: [
        {
          statusCode: '200',
          responseParameters: {
            'method.response.header.Access-Control-Allow-Origin': true,
          },
        },
      ],
      authorizationType: AuthorizationType.IAM,
    });

    // Handle deployment
    const deployment = new Deployment(this, '123_deployment', {
      api: RestApi.fromRestApiId(this, 'abc', apiCDKApiApiId),
    });
    new Stage(this, 'CDKApiStageDev', { deployment, stageName: `${ENV}` });

“taotest123deploymentC642C343” is the resource name in the Cloudformation template.

What did you expect to happen?

add salt to the resource name

What actually happened?

no salt was added to the resource name

Environment

  • **CDK CLI Version :1.83
  • Framework Version:
  • Node.js Version:
  • **OS :MAC
  • **Language (Version):TypeScript

Other

WORKAROUND: Just in case anyone ran into the same problem, you can force a deployment by manually adding salt to deployment id. in above example, 123_deployment is my deployment id, you can change the id 1234_deployment to force new deployment to deploy.


This is 🐛 Bug Report

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:14
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
nija-atcommented, Mar 22, 2021

Hi @tmclaugh - I’m keen to explore your statement here.

The addToLogicalId() method is the key to determine when a Deployment’s logical id should be modified. You can see all the uses of this method that tells the Deployment when it should be updated.

Let’s take the simple case where a RestApi is defined in one stack along with a number of Resources and Methods, and later imported into another stack using the RestApi.fromRestApiAttributes() where further Methods and Resources are defined. Unless deploy is unset, the first stack would create a Deployment construct set to latestDeployment. However, it would not be possible for this Deployment construct to know of the Methods and Resources in the second stack and therefore cannot correctly determine when its logical id should be mutated.

How do you propose your approach tackle this case?

0reactions
Durgaprasad-Budhwanicommented, Nov 11, 2022

Hey Team,

I am using the below code which is working for me.


    const deployment = new Deployment(this, `deployment-${new Date().toISOString()}`, { api: apiGateway });

    // @ts-ignore
    deployment.resource.stageName = ENV!;

    const logicalId = Date.now().toString();// salted id
    const cfnDeployment = deployment.node.defaultChild as CfnDeployment;
    cfnDeployment.overrideLogicalId(logicalId);
    

I am doing deployment two times to make it work. In the first deployment, it is creating resources and in the second deployment, it is updating stage.

This will be like


          npx aws-cdk synth
          npx aws-cdk deploy --require-approval never
          npx aws-cdk deploy --require-approval never       
Read more comments on GitHub >

github_iconTop Results From Across the Web

Deploy a REST API in API Gateway - AWS Documentation
Learn how to set up and manage API deployments in Amazon API Gateway. ... In API Gateway, a REST API deployment is represented...
Read more >
salt.modules.boto_apigateway module
Connection module for Amazon APIGateway ... Create a new REST API Service with the given name ... Gets information about the defined API...
Read more >
aws.apigateway.RestApi - Pulumi
To create and deploy WebSocket and HTTP APIs, use Amazon API Gateway Version 2 resources. !> WARN: When importing Open API Specifications with...
Read more >
Amazon API Gateway vs Salt Security API Protection Platform
API Gateway integrates well with AWS Lambda. This allows us to build a web server in the language and framework of our choice,...
Read more >
Serverless Import Apigateway
yml services and deploy each stack independently but share the same API Gateway stage/ REST API, then you want each service to use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found