aws-amplify / aws-amplify/amplify-cli

RFC: Add support for lambda resource policies and attributes for custom category

Open
#9,093 6 comments 5 reactions 0 assignees View on GitHub
feature-request functions p3
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?

custom

## Add support for lambda resource policies and attributes for custom category

Hi, would like to seek community's feedback on below proposal for Custom Category enhancement.

### Summary

Amplify Custom Category does not support lambda resources. Below proposes a new file that developers can define CRUD policy actions and attributes that can be used in functions when added as a dependency resource.

### Current

![image](https://user-images.githubusercontent.com/6001177/143495597-33f4ac94-5a93-4b7e-82e1-a16c74e10137.png)

![Screenshot 2021-11-26 at 4 06 07 AM](https://user-images.githubusercontent.com/6001177/143495803-db4149a2-3510-45ca-98b2-24e2ed66ac2b.png)

### Describe the solution you'd like
---
EDIT:
- 16 Mar - Updated resources.json to support multiple policies in create, update, read, delete.
---

1) Introduce a new file 'resources.json' in the category folder

e.g. AWS::SecretsManager::Secret
amplify -> backend -> custom -> Secrets -> resources.json

2) Resources will be loaded by Functions when trying to set custom resources

Example resources.json:
```json
{
"policies": {
"create": [],
"update": [],
"read": [
{
"Action": [
"secretsmanager:GetSecretValue"
],
"Resource": [
{
"Ref": "${categoryName}${resourceName}Arn"
}
]
}
],
"delete": []
},
"attributes": [
"Arn",
"Name"
]
}
```

Example Secrets Manager CF Template:
```yaml
AWSTemplateFormatVersion: "2010-09-09"

Parameters:
env:
Type: String
Conditions:
ShouldNotCreateEnvResources: !Equals [!Ref env, NONE]
Resources:
Secrets:
Type: AWS::SecretsManager::Secret
Properties:
Name: !Join ["", [!Ref "AWS::StackName", "-secrets-", !Ref env]]
Outputs:
Arn:
Description: Secrets ARN
Value: !Ref Secrets
Name:
Description: Secrets Name
Value: !Join ["", [!Ref "AWS::StackName", "-secrets-", !Ref env]]

```

Example Output CLI:
![image](https://user-images.githubusercontent.com/6001177/143495986-e2ec39ee-3336-452e-a2eb-f17f83581dbc.png)

Example Output function-parameters.json:
![image](https://user-images.githubusercontent.com/6001177/143496094-76cb3e27-4c09-4628-8109-b4e6494b90ed.png)

Example Output Function CF Template:
![image](https://user-images.githubusercontent.com/6001177/143496273-285a0b2f-ddd6-4255-86db-32b0cb4efd3f.png)

![image](https://user-images.githubusercontent.com/6001177/143496255-2b7d6528-d67b-4715-a799-03fc6f3688d8.png)

![image](https://user-images.githubusercontent.com/6001177/143496226-2fad212f-f9ea-498c-bdc8-2168a623ecb4.png)

### Describe alternatives you've considered

To be discussed.

### Additional context

Please refer to Pull Request #9090

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

- [X] 👋 I may be able to implement this feature request
- [ ] ⚠️ This feature might incur a breaking change

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the custom category handling and the proposed resources.json, then compare the referenced PR #9090 with the function-parameters.json and CloudFormation examples in this issue. Done means the agreed design supports custom-category Lambda resource policies and attributes when functions use the resource as a dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, json, typescript
Domain
cli, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.