duanou3868 2018-12-09 10:16
浏览 54

如何在AWS上担任角色并连接到Postgres RDS

We have a SAM-generated API-Gateway - Lambda integration stack that needs to access an RDS Database (Postgres).

SAM is creating the necessary CF template with the custom role and attendant policies for our functions: ('AWSLambdaVPCAccessExecutionRole' & 'AmazonRDSReadOnlyAccess')

We've configured the functions that need to connect to the DB with the subnetIDs and security Group of the DBs VPC and are attempting to connect using IAM authentication.

We've created the PG user account in the target DB with rds_admin role grant as per: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.DBAccounts.html

What we are not able to do is to connect to the RDS DB using the AWS SDK for Go.

It looks like the role ARN is a requirement to do so:

from the docs, link here: https://docs.aws.amazon.com/sdk-for-go/api/service/rds/rdsutils/

authToken, err := BuildAuthToken(dbEndpoint, awsRegion, dbUser, awsCreds)

// Create the MySQL DNS string for the DB connection
// user:password@protocol(endpoint)/dbname?<params>
connectStr = fmt.Sprintf("%s:%s@tcp(%s)/%s?allowCleartextPasswords=true&tls=rds",
   dbUser, authToken, dbEndpoint, dbName,
)

// Use db to perform SQL operations on database
db, err := sql.Open("mysql", connectStr)

..except we'd use a Postgres connection string.

But without creating a 'long-form' CFN template and passing the roleARN as an environment variable to our lambda function we can't work out how to configure the SDK to assume the same role as the executing lambda function.

If anyone can help work this out with me I'd be very grateful!

Thanks in advance

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 目详情-五一模拟赛详情页
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line