Deploy identical AWS CDK resources and stacks using various pipelines in Typescript

I am currently navigating my way through AWS CDK and have hit a roadblock with a specific issue.

My existing CDK code pipeline is successfully deploying a variety of resources to different environments, ultimately reaching production. It utilizes the master branch as its source and currently has a pending prod deployment awaiting production.

To enable developers to continue working, I created a new pipeline that operates on a new branch named dev. This new pipeline is designed to deploy the same set of resources to the same stacks, but exclusively in our development environment.

Upon running the new dev pipeline, I encountered the following error:

Resource handler returned message: "Usage Plan j4p4g2 cannot be added because API Key n8uyhik8h8 cannot reference multiple Usage Plans with the same API Stage: 9i1lnft358:v1 (Service: ApiGateway, Status Code: 409, Request ID: 54889a52-4fb8-4c90-93e5-31c8b1865335, Extended Request ID: null)" (RequestToken: 6fb61327-fa39-b967-8969-639daa658c72, HandlerErrorCode: AlreadyExists)

It appears that despite the identical stack name and resources, it is attempting to add a new usage plan instead of recognizing the existing one.

The second pipeline was created as follows:

if (stackBuildTargetAcct === 'dev') {

  new PipelineStack(app, 'PipelineDev', {
    environment: 'dev',
    stackName: 'dev-build-pipeline',
  })

} else if (stackBuildTargetAcct === 'prod') {
  new PipelineStack(app, 'Pipeline', {
    environment: 'prod',
    stackName: 'master-build-pipeline',
  })
}

I thought that since the stack names and resources are the same, there should be no need to create a new resource. I suspect it may be related to the 'Pipeline' versus 'PipelineDev' identifiers, but when I change them both to 'Pipeline,' I encounter an error preventing the deployment of the new pipeline:

Pipeline/Pipeline/Pipeline/ArtifactsBucketEncryptionKeyAlias (PipelineArtifactsBucketEncryptionKeyAlias94A07392) alias/codepipeline-pipelinefb9defa0 already exists in stack arn:aws:cloudformation:ap-southeast-2:master-build-pipeline

Any assistance or guidance would be greatly appreciated.

Answer №1

After some investigation, I finally cracked the code and gained a deeper insight into the issue at hand.

The root cause of the problem stems from a combination of factors:

  • One key factor is the create before delete policy in AWS CloudFormation, which means new resources are created before old ones are removed
  • Another factor is that logical IDs in CloudFormation default to different values for various pipelines
  • Furthermore, usage plans cannot reference the same API key for the same API gateway

I'd also like to point out that in our repository, we had explicit names for everything except the usage plan (which doesn't have a name) up until this point in the code base. The solution involved identifying the current logical ID used for the usage plan and setting it in the code as follows:

plan.addApiKey(importedKey, {overrideLogicalId: "<Enter the logical ID that you found is already deployed here>"})

I believe that similar issues can often be resolved by assigning an explicit name to a resource to prevent its logical ID from being randomly generated, or by overriding the logical ID in a similar manner as I had to do.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The chart JS label callback requires a specified type declaration

Currently, I am in the process of updating an old Angular platform to a newer version. One requirement is that everything must have its type declaration. I encountered a problem with the label callback showing this error: The error message reads: "Type &a ...

Using the <head> or <script> tag within my custom AngularJS2 component in ng2

When I first initiate index.html in AngularJS2, the structure looks something like this: <!doctype html> <html> <head> <title>demo</title> <meta name="viewport" content="width=device-width, initial-scal ...

Customizing the main color scheme in Naive-UI with typescript

I am a beginner with Naive and I want to change the primary color of my app theme to orange. Initially, I used vuestic for this purpose but now I am struggling to implement it. Below is my main.ts file where I had the vuestic override (commented out). Ca ...

Union types can be used to constrain generic type parameters in Typescript

I'm working on a function uniqueIds(first: any[], second: any[]): number[] { let prop = first[0] instanceof Owner ? "OwnerId" : "BankId"; return _.unique( _.map( first, o => ...

What are common pitfalls to avoid when modifying state with createSlice in Redux-Toolkit?

I am currently working with the createSlice function, specifically with the reducer setCustomEquipment that updates the state. My question is whether the = method is an acceptable way to update the state when using createSlice, or if I should always use ...

Manipulating objects within arrays in Typescript/Angular with a focus on copying

I'm currently facing issues with filtering an array using an HTML input. Here is the code snippet in question: ngOnInit() { this.dtoService.setJsonResponse(); this.getPool(); } getPool() { this.json = this.dtoService.jsonResponse; ...

Creating a new store in Redux Typescript can be challenging due to issues with the middleware

import { configureStore } from "@reduxjs/toolkit"; import { userAPI } from "./api/userAPI"; export const server = import.meta.env.VITE_SERVER; export const store = configureStore({ reducer: { [userAPI.reducerPath]: userAPI ...

Encountering type-checking errors in the root query due to the specific types assigned to my root nodes in a GraphQL and TypeScript application built using Express

As I delve into the world of typescript/graphql, I encountered a peculiar issue while trying to define the type for one of my root nodes. The root node in question simply fetches a user by ID in the resolve function, and thus, I assigned the 'type&apo ...

The function type '() => JSX.Element' cannot be assigned to the type 'ReactNode'

I am encountering an issue while trying to display a component using an object. The code is throwing an error: const Login = () => <>login</> const publicRoutes = [ { path: '/login', component: Login } ] function AppR ...

Using Javascript to incorporate a number into a UInt8Array

I need to insert a 2-byte number (ranging from 0 to 65,536) into a UInt8Array. For inserting a single byte number, I can easily refer to its index in the array like this: let bufarray = new Uint8Array(buffer); bufarray[0] = 1; However, I am unsure of how ...

Using ngFor to display images with src attribute, merging information from two different properties within the loop

One issue I am facing involves an array with properties: export interface IGameTag{ name: string; relativePath: string; filename: string; } I understand that it is possible to include the filename in the relativePath like this: <div *ngFor=" ...

An array that solely needs a single element to conform to a specific type

While I was pondering API design concepts, a thought crossed my mind. Is it feasible to define a type in this manner? type SpecialArray<Unique, Bland> = [...Bland[], Unique, ...Bland[]]; However, the error message "A rest element cannot follow anoth ...

What could be the reason behind a DynamoDB scan experiencing issues with pagination?

Currently working with DynamoDB and a DAX cluster associated with the database, I need to conduct some scans solely on the underlying database at this moment. Due to the private VPC setup for DAX, I can't access it right now, which is a separate issue ...

Guide to incorporating d.ts file for enhancing intellisense in VS Code using a method akin to the NPM approach

In my nodejs project (in JS), I find myself relying heavily on node global variables. Despite receiving warnings against using globals, everything works well except for one thing: The lack of intellisense for globals. Every time I need to use a global fu ...

Tips for retrieving the text from a POST request in C#

I have a basic Angular form that allows users to upload a file along with a description. constructor(private http: HttpClient) { } upload(files) { if (files.length === 0) return; const formData: FormData = new FormData(); var filedesc ...

fp-ts/typescript steer clear of chaining multiple pipes

Is there a more concise way to handle nested pipes in fp-ts when working with TypeScript? Perhaps using some form of syntactic sugar like Do notation? I'm trying to avoid this kind of nested pipe structure: pipe( userId, O.fold( () => set ...

One of the Amplify and AWS files that seems to be missing is the "aws-exports" module

Recently, a company interested in hiring me sent over a "trial project" to work on. It was supposed to be simple, but it required the use of Amplify and AWS. The CTO specified that I needed to have a specific version of Node (10.18.1 or 10.19.0) and instru ...

What is the process for downloading objects stored in the Glacier storage class?

After transferring my extensive collection of files from s3 storage class to Glacier storage class using a lifecycle policy for cost optimization, I encountered a prompt when attempting to access the files through the AWS Console. It requires me to resto ...

How to Resolve a Typescript Promise Syntax Error?

I have been working on creating a login authorization system to secure certain routes in an angular application, but I keep encountering a TypeScript error in the auth-guard.service during compilation. Despite my efforts, I am unable to pinpoint the issue. ...

Exploring the possibility of integrating direct search functionality into the URL bar within an Angular application

One interesting feature I observed on GitHub is that after typing "github.com" in the URL bar, you can directly search by pressing the spacebar, which activates the "search mode." Here's how it looks like on Chrome: https://i.sstatic.net/XIgJu.png I ...