Api Gateway change Stage name - amazon-web-services

How could I change Stage name in AWS API Gateway? I haven't found rename function in console and neither in CLI.
For example creating new stage with CLI:
aws apigateway create-deployment --rest-api-id ${RESTAPIID} --stage-name ''
or
aws apigateway create-stage --rest-api-id abcde123456 --stage-name ThisIsMyStageName --deployment-id abdcde
My best guess is to use "update-stage" function but don't know how to do this.

The API Gateway's stage name is a ressource ID. This mean you cannot edit it.
However, you can easily create a new stage and delete the old one

Related

AWS API GATEWAY import-documentation-parts

I am new in Api Gateway, and I am trying to dynamically update Api Gateway in my pipeline with this command.
aws apigateway import-documentation-parts --no-fail-on-warnings --rest-api-id $AWS_API_GATEWAY_REST_API_ID --mode overwrite --cli-binary-format raw-in-base64-out --body file://docs/openapi/openapi.yaml > importesdocs.json
It returns all the ids of documentation parts, but I can't see any change in my Api Gateway actually.
Then I am trying to perform new action with those ids like.
aws apigateway update-documentation-part --rest-api-id $AWS_API_GATEWAY_REST_API_ID --documentation-part-id $DOCUMENTATION_PART_ID
This haven't worked out as well. Is there any suggestion about how I can reach my goal?

Is it possible to change name of resources of API in AWS API Gateway?

I am new to AWS API Gateways. I created an api named : test-api1. Also, I created a resource named test-resource1. Now I want to change the name of this resource. I couldn't find any option to rename resources.
Is this possible or do I need to create new resource?
The answer to this depends on how you deploy your API. If you use an OpenAPI spec, then you can rename your resource there. If you used a CloudFormation template (or a AWS CDK stack) then you can rename your resource there.
If you merely clicked-together your API in the AWS Management Console (Web UI), then there isn't a way in that Web UI to change the resource's name.
You have to revert to using the AWS CLI for that.
There is the apigateway update-resource AWS CLI command to update the name of an API Gateway API resource.
https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-resource.html
(search for "To rename a resource (pathPart) in an API"):
aws apigateway update-resource --rest-api-id <api-id> --resource-id <resource-id> --patch-operations op=replace,path=/pathPart,value=<new-name>

“Lambda function ARN must be in same account” while `aws apigateway put-integration`

I am trying to follow this otherwise excellent post to deploy a Java-based AWS lambda app. I'm scripting it out as instructed in that post. I receive the following error when calling aws apigateway put-integration:
An error occurred (BadRequestException) when calling the
PutIntegration operation: Lambda function ARN must be in same account
I'm trying to script the creation of an API gateway to a lambda function. Here's the full deploy.sh script. I have on my local machine the requisite AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_ACCOUNT_ID environment variables.
I don't know enough to understand what that error is telling me. AFAIK, the access secret and id and account ID are all from the same IAM user.
My AWS CLI Script
aws apigateway put-integration --region ap-south-1 --rest-api-id xxttj6inea --resource-id bgncc0 --http-method GET --type AWS --integration-http-method POST --uri arn:aws:apigateway:ap-south-1:lambda:path/2019-09-20/functions/arn:arn:aws:lambda:ap-south-1:***********:function:Hello/invocations
Thank you very much in advance for any ideas/help.
This error can happen because of two reasons:
Your AWS CLI settings are incorrect. I'll implore you to check the AWS CLI configuration file, and run test API calls for the same to verify if everything is set up appropriately.
Your Lambda function belongs in one account, and your REST API in API GW belongs in another account.

Using multiple Lambda versions with AWS API Gateway

I have two versions of an AWS Lambda function. I wanted to attach it to two stages of API Gateway, dev and prod.
I created two aliases, dev and prod, for the two versions of the Lambda function. I created a stage variable called fname and provided the values dev and prod against them in the appropriate stages.
Against the Lambda function to be called in the Resources section, I provided the function name as stageTester:${stageVariables.fname} where stageTester is the name of my function.
It prompted me to attach permissions using AWS CLI. I ran the following command:
aws lambda add-permission --function-name arn:aws:lambda:ap-south-1:xxxxxxx:function:stageTester:dev --source-arn 'arn:aws:execute-api:ap-south-1:zzzzzz:aaaaaa/*/GET/stageTester' --principal apigateway.amazonaws.com --statement-id cxbxcx9bx5-68df-4x9d-96xd-9exb497xa934 --action lambda:InvokeFunction --profile lambdaUser --region ap-south-1
...and a similar one for prod. I expected that this would attach the permissions appropriately.
I completed the deployment and tried to invoke the API. However, I encountered Internal Server Error every time. In the Lambda function screen, against the trigger, I see the following error
The API with ID aaaaaa does not include a resource with path /stageTester
having an integration
arn:aws:lambda:ap-south-1:xxxxxxx:function:stageTester:dev on the GET
method
Can someone help me with this issue?

Create api-gateway lambda integration using aws-cli

I need to create an api gateway using aws client. I successfully create and integrate with my aws-lambda function using web console. But I am confused with aws-client. These are the steps I followed.
Create api gateway and integrate with my sample lambda function using web console.
Deploy created api and export as json file.
Create new api gateway using exported json file using aws-cli. Command like this.
aws apigateway import-rest-api --body file://tmpfile.json --region us-east-1;
But it created only resources & methods.
For integrate api method with my lambda function, I execute command like this
aws apigateway put-integration --rest-api-id 42ku123id8u3a --resource-id core-api-dev --http-method DELETE --type AWS --integration-http-method POST --uri 'arn:aws:lambda:us-east-1:my-lambda-function-arn' --region us-east-1
But it produces error message like this
An error occurred (NotFoundException) when calling the PutIntegration operation: Invalid Resource identifier specified
Is it possible to integrate api gateway method with existing lambda function using aws client? What is Resource identifier?
you can run aws apigateway get-resources to get the resource-id
aws apigateway get-resources --rest-api-id 42ku123id8u3a --region us-east-1
It will return a JSon like
{
"items": [
{
"path": "/resource/xxx",
"resourceMethods": {
"POST": {}
},
"id": "_yourresourceid_",
"pathPart": "xxx",
"parentId": "ai5b02"
}
]
}
you can take the id from this JSon and use it on your command for aws apigateway put-integration
Ideally you should export as JSON in step 2 'with integration extensions'. In the console there are 3 options for export type, and the middle one will include the integrations and authorizers in the export. Then when you import you'll have the integrations already.