UpdateFunctionConfiguration 実行時に ResourceConflictException が発生
Github Actions にて自動デプロイ中に以下のエラーが発生
Run aws lambda update-function-configuration \
aws lambda update-function-configuration \
--function-name askenFitbitSync \
--layers arn:aws:lambda:***:***:layer:AskenFitbitSyncLayer:$LAYER_VERSION \
--handler src.lambda_function.lambda_handler
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /opt/hostedtoolcache/Python/3.13.3/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.13.3/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.13.3/x64
Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.13.3/x64
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.13.3/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.13.3/x64/lib
AWS_DEFAULT_REGION: ***
AWS_REGION: ***
AWS_ACCESS_KEY_ID: ***
AWS_SECRET_ACCESS_KEY: ***
AWS_SESSION_TOKEN: ***
LAYER_VERSION: 17
An error occurred (ResourceConflictException) when calling the UpdateFunctionConfiguration operation: The operation cannot be performed at this time. An update is in progress for resource: arn:aws:lambda:***:***:function:askenFitbitSync
ログにある An update is in progress for resource
が問題点。
この処理の直前に UpdateFunctionCode で Lambda 関数コードの更新を行っていた。
そのためこの更新処理がサーバー側で完全に完了し、Lambda 関数のステータスが変更される前にレイヤ更新 UpdateFunctionConfiguration が実行されて ResourceConflictException になったと思われる。
Python 関数でキーワード引数を強制する
関数の引数定義の中で「*」を指定すると以降の引数がキーワード専用引数となり、メソッド利用時にキーワード引数指定を強制することができる。
def test(txt, *, keyword="default"):
print(txt, keyword)
test("test", keyword="keyword") # OK
test("test", "keyword") # NG
TypeError Traceback (most recent call last) Cell In[19], line 5 1 def test(txt, *, keyword="default"): 2 print(txt, keyword) ----> 5 test("test", "keyword") TypeError: test() takes 1 positional argument but 2 were given