Repository: aws-cloudformation/cfn-lint

Issue:
"Manage Amazon API Gateway" key cannot be found when running with flag --update-iam-policies
*cfn-lint version: (`cfn-lint --version`)* 0.48.0

*Description of issue.*

Running the commands:

```
pip install cfn-lint
cfn-lint --update-specs
cfn-lint --update-iam-policies
```

in an empty Python 3.8 Docker container results in the following exception:

```
Traceback (most recent call last):
    File "/usr/local/bin/cfn-lint", line 8, in <module>
      sys.exit(main())
    File "/usr/local/lib/python3.8/site-packages/cfnlint/__main__.py", line 23, in main
      (args, filenames, formatter) = cfnlint.core.get_args_filenames(sys.argv[1:])
    File "/usr/local/lib/python3.8/site-packages/cfnlint/core.py", line 144, in get_args_filenames
      cfnlint.maintenance.update_iam_policies()
    File "/usr/local/lib/python3.8/site-packages/cfnlint/maintenance.py", line 237, in update_iam_policies
      content['serviceMap']['Manage Amazon API Gateway']['Actions'].extend(
  KeyError: 'Manage Amazon API Gateway'
```

Looking at the code under `maintenance.py`, I see that the error happens after a file is downloaded on [line 226](https://github.com/aws-cloudformation/cfn-python-lint/blob/master/src/cfnlint/maintenance.py#L226). The file in question is https://awspolicygen.s3.amazonaws.com/js/policies.js, which is missing the string "Manage Amazon API Gateway". I can only find "Amazon API Gateway Management" and "Amazon API Gateway Management V2".

Unfortunately, I do not have the requisite knowledge to know which of the two is meant and if a simple swap is sufficient to submit a merge request, but would be glad to do so if a swap is sufficient.


Discussion:
I'll take a look.  Thanks for reporting this.

Resolving patch:
diff --git a/src/cfnlint/maintenance.py b/src/cfnlint/maintenance.py
--- a/src/cfnlint/maintenance.py
+++ b/src/cfnlint/maintenance.py
@@ -234,7 +234,10 @@ def update_iam_policies():
 
     content = content.split('app.PolicyEditorConfig=')[1]
     content = json.loads(content)
-    content['serviceMap']['Manage Amazon API Gateway']['Actions'].extend(
+    content['serviceMap']['Amazon API Gateway Management']['Actions'].extend(
+        ['HEAD', 'OPTIONS']
+    )
+    content['serviceMap']['Amazon API Gateway Management V2']['Actions'].extend(
         ['HEAD', 'OPTIONS']
     )
     content['serviceMap']['Amazon Kinesis Video Streams']['Actions'].append(


Test patch:
diff --git a/test/unit/module/maintenance/test_update_iam_policies.py b/test/unit/module/maintenance/test_update_iam_policies.py
--- a/test/unit/module/maintenance/test_update_iam_policies.py
+++ b/test/unit/module/maintenance/test_update_iam_policies.py
@@ -19,7 +19,7 @@ class TestUpdateIamPolicies(BaseTestCase):
     def test_update_iam_policies(self, mock_json_dump, mock_content):
         """Success update iam policies"""
 
-        mock_content.return_value = 'app.PolicyEditorConfig={"serviceMap":{"Manage Amazon API Gateway":{"Actions":[]},"Amazon Kinesis Video Streams":{"Actions":[]}}}'
+        mock_content.return_value = 'app.PolicyEditorConfig={"serviceMap":{"Amazon API Gateway Management":{"Actions":[]},"Amazon API Gateway Management V2":{"Actions":[]},"Amazon Kinesis Video Streams":{"Actions":[]}}}'
 
         if sys.version_info.major == 3:
             builtin_module_name = 'builtins'
@@ -31,7 +31,10 @@ def test_update_iam_policies(self, mock_json_dump, mock_content):
             mock_json_dump.assert_called_with(
                 {
                     'serviceMap': {
-                        'Manage Amazon API Gateway': {
+                        'Amazon API Gateway Management': {
+                            'Actions': ['HEAD', 'OPTIONS']
+                        },
+                        'Amazon API Gateway Management V2': {
                             'Actions': ['HEAD', 'OPTIONS']
                         },
                         'Amazon Kinesis Video Streams': {