aws-amplify / aws-amplify/amplify-cli
Environment variables shared across all modules cloudformation template
- 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?
function
### Is this related to another service?
_No response_
### Describe the feature you'd like to request
I'm in a multi-environment project. I need to use a lambda layer exposed by other AWS accounts. That layer is specific for each environment (amplify production environment needs the "production" layer, amplify staging environment needs the "staging" layer, and so on).
### Describe the solution you'd like
I would like to define the layer ARN as a variable in the `team-provider-info.json` file, inside the `awscloudformation` block (or a dedicated one) of each environment, like so
```
{
"staging": {
"awscloudformation": {
"AuthRoleName": "...",
"UnauthRoleArn": "...",
"...",
"MyCustomLambdaLayerArn": "arn:aws:lambda:...",
},
"categories": { ... }
},
"production": {
"awscloudformation": {
"AuthRoleName": "...",
"UnauthRoleArn": "...",
"...",
"MyCustomLambdaLayerArn": "arn:aws:lambda:...",
},
"categories": { ... }
}
```
That variable would be accessible inside each function `function-parameters.json` file, like so
```
{
"...",
"lambdaLayers": [
{
"type": "ExternalLayer",
"arn": {
"Ref": "MyCustomLambdaLayerArn"
}
}
],
"environmentVariableList": [
{
"cloudFormationParameterName": "MyCustomLambdaLayerArn",
"environmentVariableName": "MyCustomLambdaLayerArn"
}
]
}
```
This way, the cloudformation template will have the custom layer defined, and once deployed, correctly attached to the lambda.
### Describe alternatives you've considered
The way I achieved the same result is by defining the same variable inside each function block, in `team-provider-info.json` file, like so:
```
{
"staging": {
"awscloudformation": { ... },
"categories": {
"function": {
"projectPostConfirmation": {
"...",
"MyCustomLambdaLayerArn": "arn:aws:lambda:...",
}
}
}
},
"production": {
"awscloudformation": { ... },
"categories": {
"function": {
"projectPostConfirmation": {
"...",
"MyCustomLambdaLayerArn": "arn:aws:lambda:...",
}
}
}
}
```
This will create some unnecessary duplication and be error-prone.
### Additional context
My use case is related to lambda layers, but this makes sense in general, for any environment-wide variable to any Amplify module (most useful for function and custom modules).
### 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
Trace how environment values in team-provider-info.json are read and passed into function-parameters.json and the generated CloudFormation template. Start by locating the existing per-function variable flow. Done means an environment-level value can be reused by functions or other modules without duplication and the environment-specific layer is deployed correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws
- Domain
- backend, cli, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100