Search code examples
amazon-web-servicesamazon-s3aws-lambdapolicy

AWS invalid principal in bucket policy


I am writing a cfn template for S3 bucket. I have defined the principal in bucket policy as

 Principal:
    AWS:
      Fn::Join:
        - ''
        - - 'arn:aws:s3:::'
        - !Ref "AWS::AccountId"
        - ":root"

I want to make principal as the aws Account. This is giving me an invalid principal error. Please help


Solution

  • For Fn::Join you need two levels of -, and also it should be iam:

     Principal:
        AWS:
          Fn::Join:
            - ''
            - - 'arn:aws:iam::'
              - !Ref "AWS::AccountId"
              - ":root"
    

    But it would be easier to use Sub:

     Principal:
        AWS: !Sub 'arn:aws::${AWS::AccountId}:root"