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.

[aws-rds] type for input parameter for rds.Credentials.fromSecret should be ISecret

See original GitHub issue

As I understood here rds.Credentials.fromSecret(secret: secretsmanager.Secret) (link) expects a object with all the attributes of secretsmanager.Secret (link). Secret extends SecretBase . SecretBase extends Resource and implements ISecret (link). Therefore Secret has more mandatory attributes than ISecret. The function to create the Secret secretmanager.Secret.fromSecretName(scope: Construct, id: string, secretName: string): ISecret (link) return only an ISecret. When I now call the rds.Credentials.fromSecret(iSecretObject) this will never match as ISecret will always miss some attributes. So from my perspective if secretmanager.Secret.fromSecretName (link) can only return a secretsmanager.Secret then the return type should be Secret. Or if secretmanager.Secret.fromSecretName can return multiple “secret” types and all of those can be used for rds.Credentials.fromSecret(secret) then this should only expect a secret object of type ISecret.

Reproduction Steps

import * as cdk from '@aws-cdk/core';
import * as rds from '@aws-cdk/aws-rds';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
export class InfrastructureStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    const vpc = ec2.Vpc.fromLookup(this, "VPC", {
      isDefault: true
    })
    const engine = rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_12_3 });
    const mySecret = secretsmanager.Secret.fromSecretName(this, 'DBSecret', 'myDBLoginInfo');
    new rds.DatabaseInstance(this, 'InstanceWithSecretLogin', {
      engine,
      vpc,
      credentials: rds.Credentials.fromSecret(mySecret), // Get both username and password from existing secret
    });
  }
}

What did you expect to happen?

rds.Credentials.fromSecret should have accepted mySecret of type ISecret.

What actually happened?

TS2345: Argument of type 'ISecret' is not assignable to parameter of type 'Secret'.
  Type 'ISecret' is missing the following properties from type 'Secret': autoCreatePolicy, addTargetAttachment, attach, validate, and 12 more.
48       credentials: rds.Credentials.fromSecret(dbSecret),TS2345: Argument of type 'ISecret' is not assignable to parameter of type 'Secret'.
  Type 'ISecret' is missing the following properties from type 'Secret': autoCreatePolicy, addTargetAttachment, attach, validate, and 12 more.
48       credentials: rds.Credentials.fromSecret(dbSecret),

Environment

  • CLI Version : 1.68
  • Framework Version: 1.68
  • Node.js Version: v12.19.0
  • OS : OSX 10.15.6
  • Language (Version): TypeScript (3.8.3)

Other


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
skinny85commented, Oct 28, 2020

@contrapunctus-xv we should have a release this week (before October 30).

0reactions
contrapunctus-xvcommented, Oct 28, 2020

@skinny85 what’s the release cadence for this project? Would love to have this fix in soon. Thank you and @dennisseidel

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Amazon RDS uses AWS Secrets Manager
When you call the Amazon RDS Data API, you can pass credentials for the database by using a secret in Secrets Manager. For...
Read more >
Create an AWS Secrets Manager secret - AWS Workshop Studio
In the Select secret type section, choose Credentials for RDS database, then input the User name (should be masteruser ) and Password that...
Read more >
aws.secretsmanager.Secret - Pulumi
Documentation for the aws.secretsmanager.Secret resource with examples, input properties, output properties, lookup functions, and supporting types.
Read more >
Provision an RDS Instance using the AWS CDK and Secrets
We will set up an AWS Secret and System Parameter that can be used to allow other resources to connect without using plaintext...
Read more >
Terraform RDS database credentials - Stack Overflow
I would have a TF config that sets up your secret and stores it in AWS Secrets Manager, like this. resource "random_password" "master"{ ......
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