aws logs put-resource-policy failing 'parsing accessPolicy'

0

I would be grateful if someone could help me troubleshoot either incorrectly documented or out-of-date syntax on this: aws logs put-resource-policy --policy-in-json exampleResourcePolicy.json from this AWS Guide to enable IoT Analytics to send logs to CloudWatch Logs.

I executed steps 1 & 2 of the Guide successfully (I believe) and step 3 asks me to execute said line above with the following exampleResourcePolicy.json :

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "iotanalytics.amazonaws.com"
            },
            "Action": "logs:PutLogEvents",
            "Resource": "*",
            "Condition":{
                "ArnLike":{
                    "aws:SourceArn":"arn:aws:iotanalytics:us-east-1:123456789012:*/*"
                },
                "StringEquals":{
                    "aws:SourceAccount":"123456789012"
                }
            }
    ]
}

Actions I took:

  1. read the syntax for cli v2: aws logs put-resource-policy
  2. substituted --policy-in-json for --policyDocument
  3. added the required --policy-name with a value
  4. wrapped the Principal Service in square brackets like the example in --policy-document of put-resource-policy

and now I receive:

$ aws logs put-resource-policy --policy-name iotAnalytics --policy-document iot_analytics_logging_resource_policy.json

An error occurred (InvalidParameterException) when calling the PutResourcePolicy operation: Error occurred while parsing accessPolicy. Please check if the accessPolicy has been constructed correctly using IAM grammar.

So I:

  1. double-checked the results for steps 1 & 2
  2. used IAM Policy Editor - Visual - to recreate policy conditions, observe the json, compare with mine above.
  3. In the Visual Editor I added manually added "Principal" at the level shown above because the configurator wouldn't let me otherwise, and received error "Unsupported Principal: The policy type IDENTITY_POLICY does not support the Principal element. Remove the Principal element."

Should I try this instead:

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Sid": "VisualEditor0",
			"Effect": "Allow",
			"Action": "logs:PutLogEvents",
			"Resource": "*",
			"Condition": {
				"StringEquals": {
					"aws:PrincipalServiceName": "iotanalytics.amazonaws.com",
					"aws:SourceAccount": "MYACCOUNT"
				},
				"ArnLike": {
					"aws:SourceArn": "arn:aws:iotanalytics:MYREGION:MYACCOUNT:*/*"
				}
			}
		}
	]
}

with MYREGION and MYACCOUNT valid, of course, and only redacted here for security. Or should I do something else entirely? Thanks in advance!


UPDATE 7/27: This was purely a CLI syntax issue where I needed to supply the json either in a file with a file:// prefix: --policy-document file://policy.json or inline with single quotes: --policy-document '{ INSERT_JSON_HERE }' as shown in this IAM Documentation Example.

1 Antwort
1

Hi. On top of everything else, the policy document in step 3 is missing a closing brace. It should be (with brace added on 3rd last line):

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "iotanalytics.amazonaws.com"
            },
            "Action": "logs:PutLogEvents",
            "Resource": "*",
            "Condition":{
                "ArnLike":{
                    "aws:SourceArn":"arn:aws:iotanalytics:us-east-1:123456789012:*/*"
                },
                "StringEquals":{
                    "aws:SourceAccount":"123456789012"
                }
            }
        }
    ]
}

I've raised a ticket to address these errors.

profile pictureAWS
EXPERTE
Greg_B
beantwortet vor 9 Monaten
  • @Greg_B, thanks for your time, fast and exampled answer! Unfortunately, this still failed with "...InvalidParameterException...while parsing accessPolicy..." that I first mentioned. The solve was changing my cli syntax as noted in the UPDATE at the bottom of my question. Could you also raise a ticket to update the IoT Analytics Guide with the correct syntax? ie. aws logs put-resource-policy --policy-name INSERTNAME --policy-document file://policy.json

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen