LoginSignup
0
0

More than 1 year has passed since last update.

Lambda boto3 の run-instances でEBSボリュームを暗号化した時の嵌り

Last updated at Posted at 2022-05-27

Lambda 関数で boto3 を利用時、run-instances を使用して EC2 マシンを作成する際にEBSボリュームを暗号化する設定を入れると、インスタンス起動してすぐに Terminate されてしまいました。

...(snip)...
        response = client.run_instances(
            BlockDeviceMappings=[
                {
                    'DeviceName': '/dev/xvda',
                    'Ebs': {
                        'VolumeSize': 20,
                        'VolumeType': 'gp3',
                        'KmsKeyId': 'xxxx-xxxx-xxxx-xxxx-xxxx',
                        'Encrypted': True
                    }
                }
            ],
            ImageId='ami-xxxx',
...(snip)...

KMS のキーポリシに当該 Lambda 関数の実行ロールを追加したら、Terminate されなくなりました。

...(snip)...
            "Sid": "Allow use of the key",
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::<ACCOUNT-ID>:role/service-role/<ROLE>",
                    "arn:aws:iam::<ACCOUNT-ID>:user/<USER>"
                ]
            },
            "Sid": "Allow attachment of persistent resources",
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::<ACCOUNT-ID>:role/service-role/<ROLE>",
                    "arn:aws:iam::<ACCOUNT-ID>:user/<USER>"
                ]
            },
...(snip)...

(参考)
https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html#key-policy-default-allow-root-enable-iam

0
0
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
0
0