0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【AWS】エラー「does not exist or is not attachable」や「...Role is not valid.」の原因

Posted at

概要

IAM Roleにポリシーを付与した状態でcloudformationのスタックに適用すると、エラー「does not exist or is not attachable」や「...Role is not valid.」が発生しました。原因がわかったので紹介します。

原因と解決方法

まずは以下でインポートした場合。

Resources:
  LambdaRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - sns.amazonaws.com
                - lambda.amazonaws.com
            Action:
              - sts:AssumeRole
      Path: "/"
      RoleName: LambdaRole
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/AmazonSNSFullAccess
        - arn:aws:iam::aws:policy/AWSLambdaExecute
        - arn:aws:iam::aws:policy/AWSLambdaVPCAccessExecutionRole

上記だと以下のエラーになります。

Resource handler returned message: "Policy arn:aws:iam::aws:policy/AWSLambdaVPCAccessExecutionRole does not exist or is not attachable.

問題はAWSLambdaVPCAccessExecutionRoleらしい。

ポリシーではなくservice-roleにすると良いのか?

Resources:
  LambdaRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - sns.amazonaws.com
                - lambda.amazonaws.com
            Action:
              - sts:AssumeRole
      Path: "/"
      RoleName: LambdaRole
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/AmazonSNSFullAccess
        - arn:aws:iam::aws:policy/AWSLambdaExecute
        - arn:aws:iam::aws:service-role/AWSLambdaVPCAccessExecutionRole

すると今度は以下のエラー。

Resource handler returned message: "ARN arn:aws:iam::aws:service-role/AWSLambdaVPCAccessExecutionRole is not valid.

あれ、service-roleの前にpolicyつけるのか。

Resources:
  LambdaRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - sns.amazonaws.com
                - lambda.amazonaws.com
            Action:
              - sts:AssumeRole
      Path: "/"
      RoleName: LambdaRole
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/AmazonSNSFullAccess
        - arn:aws:iam::aws:policy/AWSLambdaExecute
        - arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole

ということで、上記であれば正常に適用することができました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?