Cookie の設定を選択する

当社は、当社のサイトおよびサービスを提供するために必要な必須 Cookie および類似のツールを使用しています。当社は、パフォーマンス Cookie を使用して匿名の統計情報を収集することで、お客様が当社のサイトをどのように利用しているかを把握し、改善に役立てています。必須 Cookie は無効化できませんが、[カスタマイズ] または [拒否] をクリックしてパフォーマンス Cookie を拒否することはできます。

お客様が同意した場合、AWS および承認された第三者は、Cookie を使用して便利なサイト機能を提供したり、お客様の選択を記憶したり、関連する広告を含む関連コンテンツを表示したりします。すべての必須ではない Cookie を受け入れるか拒否するには、[受け入れる] または [拒否] をクリックしてください。より詳細な選択を行うには、[カスタマイズ] をクリックしてください。

Using Psycopg3 to interact with Aurora DSQL

フォーカスモード
Using Psycopg3 to interact with Aurora DSQL - Amazon Aurora DSQL
このページはお客様の言語に翻訳されていません。 翻訳のリクエスト

Amazon Aurora DSQL is provided as a Preview service. To learn more, see Betas and Previews in the AWS Service Terms.

Amazon Aurora DSQL is provided as a Preview service. To learn more, see Betas and Previews in the AWS Service Terms.

This section describes how to use Psycopg3 to interact with Aurora DSQL.

Before you begin, make sure that you have completed the following prerequisites.

Before you get started, install the required dependency.

pip install "psycopg[binary]>=3"

Connect to an Aurora DSQL cluster and run queries

import psycopg import boto3 import os, sys def main(cluster_endpoint): region = 'us-east-1' # Generate a password token client = boto3.client("dsql", region_name=region) password_token = client.generate_db_connect_admin_auth_token(cluster_endpoint, region) # connection parameters dbname = "dbname=postgres" user = "user=admin" host = f'host={cluster_endpoint}' sslmode = "sslmode=verify-full" sslrootcert = "sslrootcert=system" password = f'password={password_token}' # Make a connection to the cluster conn = psycopg.connect('%s %s %s %s %s %s' % (dbname, user, host, sslmode, sslrootcert, password)) conn.set_autocommit(True) cur = conn.cursor() cur.execute(b""" CREATE TABLE IF NOT EXISTS owner( id uuid NOT NULL DEFAULT gen_random_uuid(), name varchar(30) NOT NULL, city varchar(80) NOT NULL, telephone varchar(20) DEFAULT NULL, PRIMARY KEY (id))""" ) # Insert some rows cur.execute("INSERT INTO owner(name, city, telephone) VALUES('John Doe', 'Anytown', '555-555-1999')") cur.execute("SELECT * FROM owner WHERE name='John Doe'") row = cur.fetchone() # Verify that the result we got is what we inserted before assert row[0] != None assert row[1] == "John Doe" assert row[2] == "Anytown" assert row[3] == "555-555-1999" # Placing this cleanup the table after the example. If we run the example # again we do not have to worry about data inserted by previous runs cur.execute("DELETE FROM owner where name = 'John Doe'") if __name__ == "__main__": # Replace with your own cluster's endpoint cluster_endpoint = "foo0bar1baz2quux3quuux4.dsql.us-east-1.on.aws" main(cluster_endpoint)

このページの内容

プライバシーサイト規約Cookie の設定
© 2025, Amazon Web Services, Inc. or its affiliates.All rights reserved.