admin管理员组

文章数量:1122846

I have the following mappings within a YAML CloudFormation file; dev, preprod and prod represent the environments. It contains roles and configurations within those environments (for a glue usage profile).

Code:

Mappings:
  GlueUsageProfileMappings:
    dev:
      DevRole:
        MinDPUs: "1"
        MaxDPUs: "40"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X"]
        RoleName: "devonly_role"
      AdminRole:
        MinDPUs: "1"
        MaxDPUs: "140"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X", "G.4X"]
        RoleName: "admin_role"

    preprod:
      DataEngineerRole:
        MinDPUs: "1"
        MaxDPUs: "40"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X"]
        RoleName: "data_engineer_role"
      AdminRole:
        MinDPUs: "1"
        MaxDPUs: "140"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X", "G.4X"]
        RoleName: "admin_role"

    prod:
      DataEngineerRole:
        MinDPUs: "1"
        MaxDPUs: "40"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X"]
        RoleName: "data_engineer_role"
      AdminRole:
        MinDPUs: "1"
        MaxDPUs: "140"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X", "G.4X"]
        RoleName: "admin_role"

I thought it looked okay,however when running a linter: cfn-lint -t ci/*.yml --ignore-checks W1001,W3005,E2010, I get the following error messages:

E7001 Mapping GlueUsageProfileMappings has invalid property at DevRole ci/master-stack.yml:433:7

E7001 Mapping GlueUsageProfileMappings has invalid property at AdminRole ci/master-stack.yml:438:7

E7001 Mapping GlueUsageProfileMappings has invalid property at DataEngineerRole ci/master-stack.yml:445:7

I've pasted this into AI tools, but they can't seem to find the issue and say my code is fine, I looked on StackOverflow and the only similar issue suggested removing the template definition at the top of the file, which I did but that didn't work either. Am I missing something here? Or maybe it is caused by something else in my file?

I looked at the docs for mappings here and can't seem to find out what I am doing wrong: .html

I have the following mappings within a YAML CloudFormation file; dev, preprod and prod represent the environments. It contains roles and configurations within those environments (for a glue usage profile).

Code:

Mappings:
  GlueUsageProfileMappings:
    dev:
      DevRole:
        MinDPUs: "1"
        MaxDPUs: "40"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X"]
        RoleName: "devonly_role"
      AdminRole:
        MinDPUs: "1"
        MaxDPUs: "140"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X", "G.4X"]
        RoleName: "admin_role"

    preprod:
      DataEngineerRole:
        MinDPUs: "1"
        MaxDPUs: "40"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X"]
        RoleName: "data_engineer_role"
      AdminRole:
        MinDPUs: "1"
        MaxDPUs: "140"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X", "G.4X"]
        RoleName: "admin_role"

    prod:
      DataEngineerRole:
        MinDPUs: "1"
        MaxDPUs: "40"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X"]
        RoleName: "data_engineer_role"
      AdminRole:
        MinDPUs: "1"
        MaxDPUs: "140"
        AllowedWorkerTypes: ["Standard", "G.1X", "G.2X", "G.4X"]
        RoleName: "admin_role"

I thought it looked okay,however when running a linter: cfn-lint -t ci/*.yml --ignore-checks W1001,W3005,E2010, I get the following error messages:

E7001 Mapping GlueUsageProfileMappings has invalid property at DevRole ci/master-stack.yml:433:7

E7001 Mapping GlueUsageProfileMappings has invalid property at AdminRole ci/master-stack.yml:438:7

E7001 Mapping GlueUsageProfileMappings has invalid property at DataEngineerRole ci/master-stack.yml:445:7

I've pasted this into AI tools, but they can't seem to find the issue and say my code is fine, I looked on StackOverflow and the only similar issue suggested removing the template definition at the top of the file, which I did but that didn't work either. Am I missing something here? Or maybe it is caused by something else in my file?

I looked at the docs for mappings here and can't seem to find out what I am doing wrong: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html

Share Improve this question asked Nov 22, 2024 at 11:44 IVB_CODINGIVB_CODING 235 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The issue stems from how AWS CloudFormation Mappings work. In CloudFormation, Mappings are key-value pairs that allow you to create mappings between logical names and their corresponding values. The structure you’ve written includes nested dictionaries (e.g., DevRole and AdminRole), which is not directly supported in the standard Mappings.

These are the two Constraints in CloudFormation Mapping:

1 - Mappings allow a key-value lookup but don’t support complex structures like nested dictionaries.

2 - Each value in the mapping must be either a simple string or a list.

and that's already stated in your provided link:

The key must be a map of name-value pairs and unique within the mapping.

The name-value pair is a label, and the value to map. By naming the values, you can map more than one set of values to a key.

The keys in mappings must be literal strings.

The values can be of type String or List.

To make this work you need to flatten the mapping structure, here's an example of how it would look like :

Mappings:
  GlueUsageProfileMappings:
    dev:
      DevRole_MinDPUs: "1"
      DevRole_MaxDPUs: "40"
      DevRole_AllowedWorkerTypes: ["Standard", "G.1X", "G.2X"]
      DevRole_RoleName: "devonly_role"
      AdminRole_MinDPUs: "1"
      AdminRole_MaxDPUs: "140"
      AdminRole_AllowedWorkerTypes: ["Standard","G.1X","G.2X","G.4X"]
      AdminRole_RoleName: "admin_role"

本文标签: amazon web servicesHow to fix invalid properties for CloudFormation mappings (YAML)Stack Overflow