Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Update Npgsql RDS IAM connection example - #149

Closed
bgrainger wants to merge 1 commit into
awsdocs:mainfrom
bgrainger:rds-iam-npgsql
Closed

bgrainger wants to merge 1 commit into
awsdocs:mainfrom
bgrainger:rds-iam-npgsql

Conversation

@bgrainger

Copy link
Copy Markdown
  • Use ProvidePasswordCallback to dynamically provide the password on demand.
    • This makes much more efficient use of connection pooling, because the connection string never changes.
    • It also avoids repeating the host and user name in two places.
  • Use using declarations to dispose resources.
    • This modernises the C# code.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Use ProvidePasswordCallback to dynamically provide the password on demand. Use 'using' declarations to dispose resources.

@roji roji left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Am not familiar with AWS authentication - is a unique token supposed to be generated for each and every individual connection? Or should users cache a single token and only rotate it after some time? If it's the latter, the callback could do that as well. But either way, the code is good as-is.

@williamdenton

Copy link
Copy Markdown

Each token is valid for 15 minutes, but because of pooling it's best to generate a new one on demand when the Connection requires it. Once the connection is open and in the pool it's not called again. It doesn't matter about the 15 minute lifetime once the connection is open.

If you're using this in a multi threaded app like an http api, and you add a log statement inside the call back, you'll see a flurry of executions as the app starts but once stable and the connection pool is populated very rarely does it ever open a new physical connection.

(I realise that both of you probably know his this works, I thought I would add some commentary for anyone else looking at this pr)

@roji

roji commented Oct 17, 2021

Copy link
Copy Markdown

Thanks for the detail @williamdenton.

Definitely better to use the callback rather than to specify the token on the connection string, since as @bgrainger explained, the latter means that pooling is effectively off, since each connection string gets its own pool.

@randyurbano randyurbano self-assigned this Oct 18, 2021
@randyurbano randyurbano assigned aditcal and unassigned randyurbano Feb 23, 2023
@joshbean

Copy link
Copy Markdown
Contributor

Closing this issue or pull request in advance of archiving this repo. For more information about the decision to archive this repo (and others in the 'awsdocs' org), see the announcement on the AWS News Blog.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants