CloudFormation stack lambda resolver template bug
Before opening, please confirm:
- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have searched for duplicate or closed issues.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
How did you install the Amplify CLI?
sudo npm install -g @aws-amplify/cli
If applicable, what version of Node.js are you using?
15.13.03
Amplify CLI Version
4.46.1
What operating system are you using?
openSUSE Leap 15.1
Amplify Categories
auth, function, api, hosting
Amplify Commands
add, push, update
Describe the bug
I try to set up simple lambda resolver, returning "Hello world" (without payload). Here stated, that to reference appropriate function I should decorate filed in schema like this
type Query {
echo: String @function(name: "echofunction-${env}")
}
After deployment with aplify push I get not ${env} construction substituted by env value, instead I have this
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"lambda:InvokeFunction"
],
"Resource": "arn:aws:lambda:eu-central-1:xxxxxxxxxxx:function:reactampifiedhello-{$env}",
"Effect": "Allow"
}
]
}
in AppSync policy and this
arn:aws:lambda:eu-central-1:xxxxxxxxxxxxx:function:reactampifiedhello-{$env}
in AppSync data sources
When I look into backend build directory, I see next construction in LambdaFunction nested Stack
"Policies": [
{
"PolicyName": "InvokeLambdaFunction",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"lambda:InvokeFunction"
],
"Resource": {
"Fn::If": [
"HasEnvironmentParameter",
{
"Fn::Sub": [
"arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:reactampifiedhello-{$env}",
{}
]
},
{
"Fn::Sub": [
"arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:reactampifiedhello-{$env}",
{}
]
}
]
}
}
]
}
}
]
and it's obvious, that env can't be substituted
Expected behavior
I expect, that ${env} should be substituted by its value in AppSync datasource tables and appsync's lambda invoking policies
Reproduction steps
- Add lambda function by
amplify function add - Insert next code into NodeJs handler
exports.handler = async (event) => {
const response = "Hello world!"
return response;
};
- Give all api permissions to this function
- Insert into schema.graphql this
type Query {
echo: String @function(name: "echofunction-${env}")
}
- Update api by
amplify update api - Push by
amplify push - Query from frontend like so
const lambdaData = await API.graphql(Object.assign(graphqlOperation(echo),{authMode: ath_mode})) - Get error in browser console
{"data":null,"errors":[{"path":["echo"],"data":null,"errorType":"Lambda:LambdaException","errorInfo":null,"locations":[{"line":2,"column":3,"sourceName":null}],"message":"1 validation error detected: Value 'arn:aws:lambda:eu-central-1:561211087447:function:reactampifiedhello-{$env}' at 'functionName' failed to satisfy constraint: Member must satisfy regular expression pattern: (arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-\\d{1}:)?(\\d{12}:)?(function:)?([a-zA-Z0-9-_\\.]+)(:(\\$LATEST|[a-zA-Z0-9-_]+))? (Service: Lambda, Status Code: 400, Request ID: 21fe17fd-afae-4628-82eb-652b067fe9a8, Extended Request ID: null)"}]}
GraphQL schema(s)
# Put schemas below this line
type Query {
echo: String! @function(name: "reactampifiedhello-{$env}")
}
Log output
# Put your logs below this line
Important additional info. I've manually fixed issue in AWS Console
- I've edited AppSync Lambda inviocing policy and set
"Resource": "arn:aws:lambda:eu-central-1:xxxxxxxxxxx:function:reactampifiedhello-dev"instead of"Resource": "arn:aws:lambda:eu-central-1:xxxxxxxxxxx:function:reactampifiedhello-{$env}" - I've edited AppSync data sources table and set resource for lambda
"Resource": "arn:aws:lambda:eu-central-1:xxxxxxxxxxx:function:reactampifiedhello-dev"instead of"Resource": "arn:aws:lambda:eu-central-1:xxxxxxxxxxx:function:reactampifiedhello-{$env}"
And after that everything gets Ок.
PS
By the way, when I add new function by amplify function add, it suggests some automatically generated name, which is 21 letter long. I've changed it with some different name, that is also 21 letter long. Then amplify later has generated name for AppSync lambda data source, it exceeded 32 letter long limit for for that name. So when I later attempted to change wrong resource arn (look p.2 before), I've not succeeded. So there is bug in data source autogeneration resource name also.
@dbelovol In the GraphQL schema details section you listed the directive as @function(name: "reactampifiedhello-{$env}") instead of @function(name: "reactampifiedhello-${env}"). Can you confirm that you are using the @function(name: "reactampifiedhello-${env}") syntax?
Oh, gosh!! Thank you.
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.