Configuring the parameters property for a SSM Association in AWS CDK

I am working on utilizing the AWS Systems Manager State Manager to automate shutting down an RDS instance at 9PM using a cron job. Currently, I am constructing the CloudFormation template with the help of AWS CDK.

While going through the AWS CDK documentation for the CfnAssociation construct, I came across the parameters property which has a type of any. I am looking for a sample on how to effectively utilize this property.

I need assistance in properly adding the parameter AutomationAssumeRole by following this code snippet. The AutomationAssumeRole requires the ARN for the role, such as

arn:aws:iam::12345678999:role/StopStartRebootRDS
.

// Setting up the State Manager association to shut down an RDS instance.
new ssm.CfnAssociation(this, 'StopRdsInstanceAssociation', {
  name: 'AWS-StopRdsInstance',
  associationName: 'StopRdsInstance',
  documentVersion: '$DEFAULT',
  instanceId: dbInstance.instanceIdentifier,
  scheduleExpression: '0 00 21 ? * * *',
  parameters: {}, // How should this be configured?
});

Your advice would be greatly appreciated.

My Attempts

Initially, I attempted to create an SSM parameter and store the Role ARN inside it. However, I realized that this approach was incorrect. I am unsure about the correct way to set this up. The error message resulting from this configuration is provided below.

const automationAssumeRole = new ssm.CfnParameter(this, 'RdsParameter', {
  type: 'String',
  value: role.roleArn,
});

// Setting up the State Manager association to shut down an RDS instance.
new ssm.CfnAssociation(this, 'StopRdsInstanceAssociation', {
  name: 'AWS-StopRdsInstance',
  associationName: 'StopRdsInstance',
  documentVersion: '$DEFAULT',
  instanceId: dbInstance.instanceIdentifier,
  scheduleExpression: '0 00 21 ? * * *',
  parameters: {
    automationAssumeRole,
  },
});

Error: Resolution error: Resolution error: Trying to resolve() a Construct at /Resources/${Token[InfrastructureDev.RdsStack.StopRdsInstanceAssociation.LogicalID.762]}/Properties/parameters/automationAssumeRole/node..

Answer №1

Directly pass the ARN of the role. The parameter key names must be in Pascal Case.

Create a new association for stopping RDS instances:

For more information, check out this AWS blog post: Schedule Amazon RDS stop and start using AWS Systems Manager. It explains how to use instance id and role effectively.

Answer №2

There is a current discussion about this specific problem on Github in an issue. After examining a suggested workaround, I have decided to utilize an alternative method to implement the changes. The solution that worked for me involves:

// Implementing the State Manager association responsible for shutting down an RDS instance.
const association = new ssm.CfnAssociation(this, 'StopRdsInstanceAssociation', {
  name: 'AWS-StopRdsInstance',
  associationName: 'StopRdsInstance',
  scheduleExpression: 'cron(0 00 2 ? * * *)',
});

// Using a different approach to modify parameters. Reference: https://github.com/aws/aws-cdk/issues/4057
association.addPropertyOverride('Parameters.InstanceId', [dbInstance.instanceIdentifier]);
association.addPropertyOverride('Parameters.AutomationAssumeRole', [role.roleArn]);

Update

I want to preserve this information for historical reference, but I have found @fedonev's solution to be effective for my situation. No need for an alternative method.

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 property you are trying to access is not defined on the enum type in Types

Looking to revise the TypeScript syntax of a lesson found at this link. I am aiming to extract a specific type from a union type using the following syntax: Actions['type'][ActionTypes.FEED_CREATE_POST] The available action types are defined a ...

Add TypeScript typings for npm utility manually by incorporating type definitions

I'm in the process of incorporating TypeScript into an existing JavaScript project, and I'm currently facing the challenge of adding typings to an npm module that lacks type definitions, which I anticipate will be a common issue. When I try to i ...

Passing parent form controls from an Angular 4 FormGroup to a child component

I have implemented Angular Reactive Forms FormGroup and FormArray in my project. The issue I am facing is related to splitting my form fields into child components and passing the parent form controls to them. I expected this to be a straightforward proces ...

What strategies can be employed to create a system for managing multiple permission groups in MongoDB effectively?

Currently, I am tackling a complex project management application which involves the challenge of setting up resource permissions for various user profiles. The task at hand: User scenario Meet John, a user with a standard user profile. John initiates a ...

Transforming a function into an array in TypeScript

I attempted to use the map() function on a dataURL array obtained from the usePersonList() hook, but I am struggling to convert my function to an array in order to avoid errors when clicking a button. import Axios from "axios"; import React, { us ...

Issue with vue-class-component: encountering TS2339 error when trying to call a method within

My vuejs application is being built using vue-cli-service. After a successful build, I encountered TS2339 errors in my webstorm IDE: Test.vue: <template> <div>{{method()}}</div> </template> <script lang="ts"> impor ...

Currently experimenting with optimal strategies for implementing useReducer and context hooks

Currently exploring the most effective approach for utilizing useReducer + context hooks. Which method is considered more optimal? Implementing one useReducer in the provider with a large initial state and multiple combined reducers. Utilizing multiple ...

Challenge with Typescript Interfaces

Can someone help me with understanding interfaces in typescript? I am currently facing an issue with the code. The error message says: Type 'Response' is missing the following properties from type 'myObj': userId, title, id I believe ...

Do I have to wait for the HTTP get request to access the fetched object property?

I am currently working with Angular and TypeScript on a dish-detail component that is accessed through 'dishes/:id' The dish object returned has a property called components, which contains an array of objects with two properties: id: type stri ...

Using Typescript to change a JSON array of objects into a string array

I'm currently working with the latest version of Angular 2. My goal is to take a JSON array like this: jsonObject = [ {"name": "Bill Gates"}, {"name": "Max Payne"}, {"name": "Trump"}, {"name": "Obama"} ]; and convert it into a st ...

How can the `!` operator be utilized in MikroORM Typescript entities?

How can I declare a key in a JS object with an ! before the colon? MikroORM syntax for class @Entity() export class Post { // Using @PrimaryKey() decorator to designate primary key @PrimaryKey() id!: number; @Property({ type: "date", de ...

Is there a way to turn off the "defer" feature in an Angular build?

After compiling my Angular project, I noticed that the compiler automatically adds the "defer" attribute to the script tag in my "index.html" file. However, I need to disable this feature. Is there a way to do it? I am currently working with Angular versi ...

Execute the function right away and then at regular intervals of X seconds

Need help with Angular 7 function call timing checkData(): Observable<string> { return this.http.get('') .pipe( map(res => { let result; result = { packageNumbe ...

Troubleshooting Problem in Angular 6: Difficulty in presenting data using *ngFor directive (data remains invisible)

I came across a dataset that resembles the following: https://i.sstatic.net/S0YyO.png Within my app.component.html, I have written this code snippet: <ul> <li *ngFor="let data of myData">{{data.id}}</li> </ul> However, when I ...

Mastering the integration of NestJS with Redis for microservices

Currently, I am diving into the world of nestjs microservices. I am curious, what commands are available for me to use? const pattern = { cmd: 'get' }; this.client.send<any>(pattern, data) Additionally, how do I go about retrieving data ...

The synergy between JSDoc and type mapping

I am in search of a comprehensive and reliable source that provides detailed information on how TypeScript's JSDoc interacts with types, their mappings, and modifications. It is widely known that Pick and Omit maintain the original JSDoc: const any: ...

Avoiding the use of destructuring for undefined values in JavaScript can be achieved by implementing

Upon receiving the response registryReportSettings from the server: this.getRegistrySettings(registry.Id).subscribe((registryReportSettings: { extended: ReportPropertiesRequest }) => { const { objectProperties, reportProperties, textProperties } = reg ...

Outputting undefined values when processing an http post array

I seem to have encountered a major issue. Despite my efforts, I am seeing an undefined value when trying to display this JSON data. {"StatusCode":0,"StatusMessage":"OK","StatusDescription":{ "datas": [ {"sensor_serial":"SensorSerial1", "id":"11E807676E3F3 ...

Error encountered while retrieving data from Firebase and storing it in an array within an IONIC application

I am currently working on a function that retrieves data from Firebase's real-time database and stores it in an array for mapping in React. However, I am encountering a TypeScript error that I'm having trouble resolving. The error message reads ...

Using TypeScript to create a generic function that returns a null value

In my Typescript code, I have the following function: In C#, you can use default(T), but I'm not sure what the equivalent is in Typescript. public Base { ... } public Get<T extends Base>(cultura: string): T[] { let res = null; try ...