Hello, any chance to get the RDS DbiResourceId? I ...
# aws
o
Hello, any chance to get the RDS DbiResourceId? I want to setup iam authentication to the database. aws rds describe-db-instances --query "DBInstances[?DBInstanceIdentifier=='mydbname'].DbiResourceId | [0]"
l
Hey @orange-zoo-84739, if you're creating a RDS instance with Pulumi then you can refer to its resource id by doing something like
const rdsResourceId = <rds-instance-name>.resourceId
, Here is the link to the outputs supported: https://www.pulumi.com/registry/packages/aws/api-docs/rds/instance/#look-up If your trying to get the resource id of an instance that exists already and wasn't created by Pulumi, you can use the get function that Pulumi provides: https://www.pulumi.com/registry/packages/aws/api-docs/rds/instance/#look-up
o
But I need the DbiResourceId. Thats a different number. The bottom one.
l
Yes, there is the
id
output and there is also a
resourceId
output. The second one will get you the value that you're looking for
o
Ah, thanks, sst around pulumi has had that hidden. But the is a way to get the actual instance reference from sst that works.
l
Understood, if you can please share your solution so that if anybody stumbles on this thread they can see whats possible
o
Copy code
// auto creates a database in the rds server
    const db = new sst.aws.Mysql("MetropolGuruDatabase", {
      vpc,
      version: "8.4.6",
      storage: "20 GB",
      transform: {
        instance: (args, opts) => { 
          args.iamDatabaseAuthenticationEnabled = true // Client would need a way to calculate the correct tokens
        }
      },
      // use your local docker db for strapi on dev mode
      dev: {
        host: "127.0.0.1",
        port: 3306,
        username: "strapi",
        password: "strapi",
        database: "strapi"
      }
    });

    const strapiAndAstroWebServerDbAccess = new aws.iam.Policy("StrapiAndAstroWebServerDbAccess", {
      name: "StrapiAndAstroWebServerDbAccess",
      policy: aws.iam.getPolicyDocumentOutput({
        statements: [
          {
            actions: [
                "rds-db:connect"
            ],
            resources: [$interpolate`arn:aws:rds-db:eu-central-1:${accountId}:dbuser:${db.nodes.instance?.resourceId}/strapi`]
          }
        ]
      }).json},
      {
        dependsOn: [db]
      }
    );
🙏 1