Skip to content

(gen2-migration) generate command should handle function to geo resources access #14806

@sai-ray

Description

@sai-ray

Is this feature request related to a new or existing Amplify category?

No response

Is this related to another service?

No response

Describe the feature you'd like to request

In Gen1 functions can be configured to access other functions. For example:

? Do you want to access other resources in this project from your Lambda function? Yes
? Select the categories you want this function to have access to. geo
? Geo has 3 resources in this project. Select the one you would like your Lambda to access map7c2057b4, geofenceCollection1f728878, placeIndex4173f677
? Select the operations you want to permit on map7c2057b4 create, read, update, delete
? Select the operations you want to permit on geofenceCollection1f728878 create, read, update, delete
? Select the operations you want to permit on placeIndex4173f677 create, read, update, delete

You can access the following resource attributes as environment variables from your Lambda function
	ENV
	GEO_GEOFENCECOLLECTION1F728878_NAME
	GEO_MAP7C2057B4_NAME
	GEO_PLACEINDEX4173F677_NAME
	REGION

Describe the solution you'd like

Internally it create the following relevant parts in cfn template:

IAM Permissions:

"AmplifyResourcesPolicy": {
      "DependsOn": [
        "LambdaExecutionRole"
      ],
      "Type": "AWS::IAM::Policy",
      "Properties": {
        "PolicyName": "amplify-lambda-execution-policy",
        "Roles": [
          {
            "Ref": "LambdaExecutionRole"
          }
        ],
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Action": [
                "geo:CreateMap",
                "geo:DescribeMap",
                "geo:GetMapGlyphs",
                "geo:GetMapSprites",
                "geo:GetMapStyleDescriptor",
                "geo:GetMapTile",
                "geo:DeleteMap"
              ],
              "Resource": [
                {
                  "Fn::Join": [
                    "",
                    [
                      "arn:aws:geo:",
                      {
                        "Ref": "AWS::Region"
                      },
                      ":",
                      {
                        "Ref": "AWS::AccountId"
                      },
                      ":map/",
                      {
                        "Ref": "geomap7c2057b4Name"
                      }
                    ]
                  ]
                }
              ]
            },
            {
              "Effect": "Allow",
              "Action": [
                "geo:CreateGeofenceCollection",
                "geo:DescribeGeofenceCollection",
                "geo:DeleteGeofenceCollection"
              ],
              "Resource": [
                {
                  "Fn::Join": [
                    "",
                    [
                      "arn:aws:geo:",
                      {
                        "Ref": "AWS::Region"
                      },
                      ":",
                      {
                        "Ref": "AWS::AccountId"
                      },
                      ":geofence-collection/",
                      {
                        "Ref": "geogeofenceCollection1f728878Name"
                      }
                    ]
                  ]
                }
              ]
            },
            {
              "Effect": "Allow",
              "Action": [
                "geo:CreatePlaceIndex",
                "geo:DescribePlaceIndex",
                "geo:SearchPlaceIndexForPosition",
                "geo:SearchPlaceIndexForText",
                "geo:SearchPlaceIndexForSuggestions",
                "geo:GetPlace",
                "geo:DeletePlaceIndex"
              ],
              "Resource": [
                {
                  "Fn::Join": [
                    "",
                    [
                      "arn:aws:geo:",
                      {
                        "Ref": "AWS::Region"
                      },
                      ":",
                      {
                        "Ref": "AWS::AccountId"
                      },
                      ":place-index/",
                      {
                        "Ref": "geoplaceIndex4173f677Name"
                      }
                    ]
                  ]
                }
              ]
            }
          ]
        }
      }
    }

Environment Variables

"Environment": {
          "Variables": {
            "ENV": {
              "Ref": "env"
            },
            "REGION": {
              "Ref": "AWS::Region"
            },
            "GEO_MAP7C2057B4_NAME": {
              "Ref": "geomap7c2057b4Name"
            },
            "GEO_GEOFENCECOLLECTION1F728878_NAME": {
              "Ref": "geogeofenceCollection1f728878Name"
            },
            "GEO_PLACEINDEX4173F677_NAME": {
              "Ref": "geoplaceIndex4173f677Name"
            }
          }
        }

The generate command should inspect this template (similarly to what it does for other function access types) and generate the necessary gen2 code.

Describe alternatives you've considered

None

Additional context

No response

Is this something that you'd be interested in working on?

  • 👋 I may be able to implement this feature request

Would this feature include a breaking change?

  • ⚠️ This feature might incur a breaking change

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions