aws-amplify / aws-amplify/amplify-cli
(gen2-migration) `generate` command should handle function to geo resources access
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### 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:
```cli
? 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:**
```yaml
"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**
```yaml
"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
Contributor guide
Research direction
Start with the generate command's existing handling for other function access types and the CloudFormation template inspection described in the issue. Confirm that geo map, geofence collection, and place index resources produce the corresponding IAM permissions and environment variables in the generated Gen 2 code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cli, cloud
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100