Deleting rest api methods
How did you install the Amplify CLI?
npm install -g @aws-amplify/cli
If applicable, what version of Node.js are you using?
v18.19.0
Amplify CLI Version
12.11.1
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
Created resources for rest api from AWS console as i am unable to create resource from cli.
Describe the bug
1- Unable to create resource (I.e GET, POST methods) from the amplify cli, when i run amplify update api it only give option to update path, but i want to create resource.
2- When i create resource from the aws cli and then push my local code, it removes my resources (created from cli), along with that it also removes my authoriser...
Expected behavior
1- Should provide option to create resource from cli 2- Must not delete the resources created from console, The possible solution could be when we created anything from console and do amplify pull on code, so it must sync the changes rather delete resources created from console.
Reproduction steps
create api from cli with following commands: amplify add api choose the path choose existing lambda etc
So there is no option to add any resource i.e GET, POST methods etc
Now when you create resource from aws console and run amplify pull it does not fetch the changes done on console
Project Identifier
No response
Log output
# Put your logs below this line
Additional information
No response
Before submitting, please confirm:
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.
Hey @MrFarhan, thank you for reaching out. The REST API currently only support creating path with Lambda proxy integration which should support all the methods request. But if you are looking to use an existing API/custom API in your project you can use the Amplify configure method to interact with the API, refer to https://docs.amplify.aws/react/build-a-backend/restapi/existing-resources/ providing this information. Furthermore with Amplify Gen 2, you can create a REST API using the AWS CDK constructs to your specifications and interact with the API using Amplify Library.
My Question was specifically about creating http methods (GET, POST etc) from amplify cli, the issue is while creating the apis with cli it does not provide option for lambda proxy integration / creating http methods.
@MrFarhan this is currently not supported with Amplify CLI. This is currently being tracked on https://github.com/aws-amplify/amplify-category-api/issues/316. Refer to the comment https://github.com/aws-amplify/amplify-category-api/issues/316#issuecomment-1129357342 providing this information.
Closing the issue due to inactivity. Do reach out to us if you are still experiencing this issue
This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.
By default, the Amplify CLI overrides all resources created or updated from the console when you push your API using the CLI. To work around this, you can enable overriding using the following command:
amplify override api
As mentioned in the documentation, you can make any customized changes inside the override function.
Example: Removing {proxy+} Path and ANY Methods
To remove the {proxy+} path and ANY methods, use the following code snippet:
const { paths } = resources.restApi.body;
// For every path in your REST API
for (const path in paths) {
// Check if the path contains "{proxy+}"
if (path.includes('{proxy+}')) {
delete paths[path];
}
// Check if the path has an "ANY" method
if (paths[path]['x-amazon-apigateway-any-method']) {
// Remove the "ANY" method from the path
delete paths[path]['x-amazon-apigateway-any-method'];
}
}
Example: Retaining Methods on Route Updates
If you want to retain your methods when updating routes using the CLI, add the following code snippet:
const functionResourcename = "your-function-name";
const functionArnParameter = "FunctionArn";
resources.addCfnParameter(
{
type: "String",
description: "The ARN of an existing Lambda Function to authorize requests",
default: "NONE",
},
functionArnParameter,
{ "Fn::GetAtt": [`function${functionResourcename}`, "Outputs.Arn"] }
);
resources.restApi.addPropertyOverride('Body.paths./example.post', {
"x-amazon-apigateway-integration": {
"type": "aws_proxy",
"httpMethod": "POST",
"uri": {
'Fn::Join': [
'',
[
"arn:aws:apigateway:",
{ Ref: 'AWS::Region' },
":lambda:path/2015-03-31/functions/",
{ Ref: functionArnParameter },
"/invocations"
]
],
},
"passthroughBehavior": "WHEN_NO_MATCH",
"timeoutInMillis": 29000
},
// Add Cognito authorization
"security": [
{ "Cognito": [] }
]
});
Keep appending your routes along with their specified methods one be one just like the above one (
/example.post)
Note: Make sure to change the functionResourcename variable to the name of the function in your project. It is actually the folder name at /amplify/backend/function/<resource-name>.