aws-amplify / aws-amplify/amplify-cli
Adding stack dependency from hosting to function
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### Amplify CLI Version
12.10.0
### Question
I am trying to use CloudFormation to automate the deployment of Lambda@Edge with a CloudFront distribution. I have a Lambda function which I created with `amplify add function`. I also added S3 and CloudFront hosting with `amplify add hosting`. I added versioning to my function template, and I am outputting the qualified ARN:
```js
"Version": {
"Type": "AWS::Lambda::Version",
"Properties": {
"FunctionName": {
"Ref": "LambdaFunction"
}
}
}
// ...
"Outputs": {
"QualifiedARN": {
"Value": {
"Ref": "Version"
}
}
}
```
However, in order for the CloudFront template to be able to use this output, I need to change the stack deployment order so that the Lambda function gets deployed before the CloudFront distribution. And, in order to do this, I figured the easiest way would be to use this new `QualifiedARN` output as a parameter in the hosting template. But, in order to add this parameter, I need to modify the root stack template _after_ it is built but before it is uploaded to CloudFormation. I explored adding a project-wide override, but I don't think that will let me do what I need it to. I did also try using a file system watcher to wait for the root template build output to be overwritten, at which point a script would go and add the new parameter, but that didn't seem to work either.
In essence, inside the root stack template, I need my hosting resource to look like this:
```json
"hostingS3AndCloudFront": {
"Type": "AWS::CloudFormation::Stack",
"Properties": {
"TemplateURL": "should I redact this?",
"Parameters": {
"bucketName": "project-20231217154634-hostingbucket",
"env": "dev",
"resolverQualifiedArn": {
"Fn::GetAtt": [
"functionmylambda",
"Outputs.QualifiedARN"
]
}
}
}
}
```
Is this something that can be done?
Contributor guide
Research direction
Start with the Amplify CLI flow that builds and uploads the root stack template, then inspect the generated hosting and function templates. Trace whether the function's QualifiedARN output can be passed into the hosting nested stack as a parameter before CloudFormation deployment. Done means confirming whether this dependency-ordering and parameter wiring are supported, and identifying the documented extension point if they are not.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws
- Domain
- cli, cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100