LoginSignup
2
2

More than 3 years have passed since last update.

Aurora Severless Data API を使ってみての気づき

Last updated at Posted at 2020-05-07

この記事は何?

Aurora Severless Data API を利用した開発活動中に気づいたことを随時記載します。
Data API については、昨年(2019年)に東京リージョンでリリースされたばかりであるため、日本語の情報が少ない状況です。この記事が今後利用される方のお役に立てば幸いです。

RDS 利用環境

  • リージョン:ap-northeast-1
  • ロール:サーバーレス
  • エンジン:Aurora PostgreSQL

Aurora Severless (PostgreSQLエンジン)を使ってみての気づき

:one: 最小キャパシティーを1Aurora Capacity Unit (ACU) から設定できるのはMySQLエンジンのみ。

PostgreSQLエンジンの最小キャパシティーは2ACU。
Amazon Aurora Serverless が 1 ユニットのキャパシティーと新しいスケーリングオプションのサポートを開始」という発表を聞いて、選択するエンジンに関わらず1ACUから設定できると考えていたのですが

MySQL と互換性のある Aurora Serverless DB クラスターの最小キャパシティーを 1 Aurora Capacity Unit (ACU) に設定できるようになりました。

  とのことです :innocent:

:two: プレースホルダーに渡す値のデータ型が少ない。ARRAY型、JSON型は2020年5月時点で非サポート。

ExecuteStatementアクションの公式ドキュメントを読むと、リクエストシンタックスには一見ARRAY型をサポートしているような記載がありますが、次の注意書きがありました。

:information_source: Note
Array parameters are not supported.

 気になったので試しに、boto3からプレースホルダーへARRAY型の値を渡すようにExecuteStatementを実行したところ、「Array parameters are not supported」エラーが発生しました。調べたところ、GitHubでも Issues として Open になっており、AWSのエンジニアが次のようにコメントしていることから今後ARRAY型をサポートするものと考えます

The SDK team has already things set up, its up-to the service team the time they take to implement it. Will update if they implement the feature.

 ワークアラウンドな対応となりますが、次のような記述をすることでARRAY型のプレースホルダーへ値を渡すことが可能です

tags = ['tag1', 'tag2']

rds_client = boto3.client('rds-data')
parameters = {
    'secretArn': 'your_secret_arn',
    'resourceArn': 'your_resource_arn',
    'sql': INSERT INTO sample_tbl (id, tags) VALUES (:id, :tags::text[]),
    'parameters': [
        {'name':'id', 'value':{'stringValue': '001'},
        {'name':'tags', 'value':{'stringValue': '{' + ','.join(tags) + '}'}}
    ],
    'database': 'your_database_name',
}

response = rds_client.execute_statement(**parameters)

:three: トランザクションのタイムアウト値は3分。

BeginTransactionアクションの公式ドキュメントによると、発行したトランザクションIDが使用されない場合、トランザクションは3分間でタイムアウトします。コミットされる前にタイムアウトする場合は、自動でロールバックが実行されます。
また、一度使用されたトランザクションは最大24時間有効で、24時間後に自動で終了し、ロールバックが実行されます。

:warning: Important
A transaction can run for a maximum of 24 hours. A transaction is terminated and rolled back automatically after 24 hours.
A transaction times out if no calls use its transaction ID in three minutes. If a transaction times out before it's committed, it's rolled back automatically.

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2