AWS API GATEWAY import-documentation-parts - amazon-web-services

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?

Related

Api Gateway change Stage name

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

How to add headers in existing AWS API gateway integration request

I have created a Integration Request, I am trying to add headers to that request using AWS cloudshell:
aws apigateway update-integration --rest-api-id abcdefgh --resource-id
abcdefghj --http-method POST --request-parameters
{"integration.request.header.X-mobile":"context.authorizer.mobile"}
But it is not working, I have tried PUT integration as well, It was giving the below error:
An error occurred (BadRequestException) when calling the
PutIntegration operation: Enumeration value for HttpMethod must be
non-empty
Try add those command options:
--integration-type eg. AWS_PROXY
--integration-method eg. POST
--integration-uri eg. arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaForSimpleProxy.Arn}/invocations
Here you will find values exmple: Lambda Proxy
I had similar issue in cloudformation, when you are using integration some options are conditional AWS::ApiGateway::Method Integration
Unfortunately aws cli docs doesn't mention this.
Adding
--integration-http-method POST
solved it for me when doing this with AWS CLI.
As per the documentation:
For Lambda integrations, you must use the HTTP method of POST for the
integration request, according to the specification of the Lambda
service action for function invocations.

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.

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.