@Charcoal_4C444D

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

AWS SAM AWS::Serverless::Function で RuntimeManagementConfig と AutoPublishAlias を同時に定義するとエラーになってしまう

解決したいこと

AWS SAMテンプレートの
「AWS::Serverless::Function」
でランタイムの更新管理の設定項目「RuntimeManagementConfig」と「AutoPublishAlias」を同時に設定したいのですが、コンソールマネジメントのCloudFormationからテンプレートを実行させるとエラーになってしまいます。
解決方法がわかる方がいたらご共有いただきたいです。

エラーになるソースコード

AWSTemplateFormatVersion: 2010-09-09

Transform: AWS::Serverless-2016-10-31

Resources:
  TestLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      RuntimeManagementConfig:
        UpdateRuntimeOn: FunctionUpdate
      Description: 'test'
      Architectures:
      - arm64
      Runtime: python3.10
      Timeout: 15
      Handler: main.lambda_handler
      MemorySize: 128
      EphemeralStorage:
        Size: 512
      AutoPublishAlias: alias
      FunctionName: test_lambda_function
      CodeUri:
        Bucket: testBucket
        Key: test.zip
      AutoPublishAliasAllProperties: true
      VersionDescription: varsion test

エラー内容

AWS::Lambda::Version には「RuntimeManagementConfig」なんて項目はないよ的な怒られ方です

image.png

変更セットでCloudFormation形式にコンバートされたテンプレートを確認

確かにAWS::Lambda::Version に「RuntimeManagementConfig」が記載されてしまっています。。。

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "TestLambdaFunction": {
      "Type": "AWS::Lambda::Function",
      "Properties": {
        "Code": {
          "S3Bucket": "testBucket",
          "S3Key": "test.zip"
        },
        "Description": "test",
        "FunctionName": "test_lambda_function",
        "Handler": "main.lambda_handler",
        "MemorySize": 128,
        "Role": {
          "Fn::GetAtt": [
            "TestLambdaFunctionRole",
            "Arn"
          ]
        },
        "Runtime": "python3.10",
        "Timeout": 15,
        "Tags": [
          {
            "Key": "lambda:createdBy",
            "Value": "SAM"
          }
        ],
        "Architectures": [
          "arm64"
        ],
        "EphemeralStorage": {
          "Size": 512
        },
        "RuntimeManagementConfig": {
          "UpdateRuntimeOn": "FunctionUpdate"
        }
      }
    },
    "TestLambdaFunctionVersion5e803e28a1": {
      "Type": "AWS::Lambda::Version",
      "DeletionPolicy": "Retain",
      "Properties": {
        "Description": "varsion test",
        "FunctionName": {
          "Ref": "TestLambdaFunction"
        },
        "RuntimeManagementConfig": {
          "UpdateRuntimeOn": "FunctionUpdate"
        }
      }
    },
    "TestLambdaFunctionAliasalias": {
      "Type": "AWS::Lambda::Alias",
      "Properties": {
        "Name": "alias",
        "FunctionName": {
          "Ref": "TestLambdaFunction"
        },
        "FunctionVersion": {
          "Fn::GetAtt": [
            "TestLambdaFunctionVersion5e803e28a1",
            "Version"
          ]
        }
      }
    },
    "TestLambdaFunctionRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Action": [
                "sts:AssumeRole"
              ],
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "lambda.amazonaws.com"
                ]
              }
            }
          ]
        },
        "ManagedPolicyArns": [
          "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
        ],
        "Tags": [
          {
            "Key": "lambda:createdBy",
            "Value": "SAM"
          }
        ]
      }
    }
  }
}

試したこと

・「AutoPublishAlias」を削除 -> デプロイできるがバージョンとエイリアスが作成されないため却下
・「RuntimeManagementConfig」を削除しデプロイ後に手動で設定 -> 可能だが手動作業は入れたくない
・初めからCloudFormationの形式で記述 -> テンプレートが複雑になるため極力避けたい

0 likes

No Answers yet.

Your answer might help someone💌