Not able to attach custom authorizer to aws api gateway through openapi specifications - openapi

We have an API gateway with many routes managed by terraform API gateway resources. As the number of routes increased, it was difficult to manage them from the resources. Hence, we are trying to move it to the body method with merge so that the new routes can be added by importing openapi spec with amazon extensions. But the custom lambda authorizer is not getting attached to the method request.
OpenAPI Spec:
openapi_config = {
openapi = "3.0.1"
info = {
title = "im-dev-api-gateway"
version = "1.0"
}
paths = {
"/v1/api/go/data" : {
"post" : {
"parameters" : [{
"name" : "proxy",
"in" : "path",
"required" : true,
"schema" : {
"type" : "string"
}
}],
"responses" : {
"200" : {
"description" : "200 response",
"headers" : {
"Access-Control-Allow-Origin" : {
"schema" : {
"type" : "string"
}
}
},
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/Empty"
}
}
}
}
},
"security" : [{
"im-dev-lambda-authorizer" : []
}],
"x-amazon-apigateway-integration" : {
"httpMethod" : "POST",
"uri" : "https://$${stageVariables.LoadBalancerURL}/v1/api/go/data",
"requestParameters" : {
"integration.request.header.X-Auth-Client-ID" : "context.authorizer.x-auth-client-id",
"integration.request.path.proxy" : "method.request.path.proxy",
"integration.request.header.X-Request-ID" : "context.authorizer.x-request-id"
},
"passthroughBehavior" : "when_no_match",
"timeoutInMillis" : 29000,
"type" : "http_proxy"
}
},
"options" : {
"responses" : {
"200" : {
"description" : "200 response",
"headers" : {
"Access-Control-Allow-Origin" : {
"schema" : {
"type" : "string"
}
},
"Access-Control-Allow-Methods" : {
"schema" : {
"type" : "string"
}
},
"Access-Control-Allow-Headers" : {
"schema" : {
"type" : "string"
}
}
},
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/Empty"
}
}
}
}
},
"x-amazon-apigateway-integration" : {
"responses" : {
"default" : {
"statusCode" : "200",
"responseParameters" : {
"method.response.header.Access-Control-Allow-Methods" : "'GET,OPTIONS,POST,PUT'",
"method.response.header.Access-Control-Allow-Headers" : "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Auth-Client-ID,X-Request-ID'",
"method.response.header.Access-Control-Allow-Origin" : "'*'"
}
}
},
"requestTemplates" : {
"application/json" : "{\"statusCode\": 200}"
},
"passthroughBehavior" : "never",
"timeoutInMillis" : 29000,
"type" : "mock"
}
}
},
"components" : {
"schemas" : {
"Empty" : {
"title" : "Empty Schema",
"type" : "object"
}
},
"securitySchemes" : {
"im-dev-lambda-authorizer" : {
"type" : "apiKey",
"name" : "Unused",
"in" : "header",
"x-amazon-apigateway-authtype" : "custom",
"x-amazon-apigateway-authorizer" : {
"authorizerUri" : "arn:aws:apigateway:ap-south-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-south-1:999999999:function:im-dev-authorizer/invocations",
"authorizerCredentials" : "arn:aws:iam::999999999:role/im-dev-api-gateway-auth-invocation",
"authorizerResultTtlInSeconds" : 0,
"identitySource" : "context.$context.requestId",
"type" : "request"
}
}
}
},
}
}
}

Related

Opensearch index mapping field value not searchable

I am new at Opensearch and using this code on DevTools to make media_image_thumbnail_url field not searchable but having error like index already exist.
PUT cars
{
"mappings" : {
"properties" : {
"fields" : {
"properties" : {
"media_image_thumbnail_url" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
},
"enable":false
}
}
}
}
}
}
}
This one solved my issue
PUT cars/_mappings
{
"properties" : {
"fields" : {
"properties" : {
"media_image_thumbnail_url" : {
"type" : "text",
"fields": {
"raw": {
"type": "text",
"index": "false"
}
}
}
}
}
}
}

swagger file for all possible 'properties'

I need to call an API to load data on an ongoing basis. API returns different properties for each event. When I create the swagger file it has properties from sample return, but in the long run there will be more properties which can be added by the source system and they will not be in swagger file.
Is there any way to recreate swagger file before data load dynamically with additional properties?
Swagger file is generated by Informatica Cloud based on a sample return while testing the connection.
Properties list has a different number of entries based on event type.
swagger file:
{"swagger" : "2.0",
"info" : {
"description" : null,
"version" : "1.0.0",
"title" : null,
"termsOfService" : null,
"contact" : null,
"license" : null
},
"host" : "<host>.com",
"basePath" : "/api",
"schemes" : [ "https" ],
"paths" : {
"/2.0" : {
"post" : {
"tags" : [ "events" ],
"summary" : null,
"description" : null,
"operationId" : "events",
"produces" : [ "application/json" ],
"consumes" : [ "application/json" ],
"parameters" : [ {
"name" : "script",
"in" : "query",
"description" : null,
"required" : false,
"type" : "string"
}, {
"name" : "Authorization",
"in" : "header",
"description" : null,
"required" : false,
"type" : "string"
} ],
"responses" : {
"200" : {
"description" : "successful operation",
"schema" : {
"$ref" : "#/definitions/events"
}
}
}
}
}
},
"definitions" : {
"events##properties" : {
"properties" : {
"$app_build_number" : {
"type" : "string"
},
"$app_version_string" : {
"type" : "string"
},
"$carrier" : {
"type" : "string"
},
"$lib_version" : {
"type" : "string"
},
"$manufacturer" : {
"type" : "string"
},
"$model" : {
"type" : "string"
},
"$os" : {
"type" : "string"
},
"$os_version" : {
"type" : "string"
},
"$radio" : {
"type" : "string"
},
"$region" : {
"type" : "string"
},
"$screen_height" : {
"type" : "number",
"format" : "int32"
},
"$screen_width" : {
"type" : "number",
"format" : "int32"
},
"Home Step Enabled" : {
"type" : "string"
},
"Number Of Lifetime Logins" : {
"type" : "number",
"format" : "int32"
},
"Sessions" : {
"type" : "number",
"format" : "int32"
},
"mp_country_code" : {
"type" : "string"
},
"mp_lib" : {
"type" : "string"
}
}
},
"events" : {
"properties" : {
"name" : {
"type" : "string"
},
"distinct_id" : {
"type" : "string"
},
"labels" : {
"type" : "string"
},
"time" : {
"type" : "number",
"format" : "int64"
},
"sampling_factor" : {
"type" : "number",
"format" : "int32"
},
"dataset" : {
"type" : "string"
},
"properties" : {
"$ref" : "#/definitions/events##properties"
}
}
}
}
}
sample return:
"name": "Session",
"distinct_id": "1234567890",
"labels": [],
"time": 1520072505000,
"sampling_factor": 1,
"dataset": "$event_data_set",
"properties": {
"$app_build_number": "900",
"$app_version_string": "1.9",
"$carrier": "AT&T",
"$lib_version": "2.0.1",
"$manufacturer": "Apple",
"$model": "iPhone10,6",
"$os": "iOS",
"$os_version": "11.2.6",
"$radio": "LTE",
"$region": "Florida",
"$screen_height": 667,
"$screen_width": 375,
"Number Of Lifetime Logins": 2,
"Session Length": "00h:00m:08s",
"Sessions": 43,
"mp_country_code": "US",
"mp_lib": "swift"
}
}

Invalid mapping expression parameter specified

I am trying to write a Swagger config for the AWS API Gateway deployment, and came up with this for a sample (mostly copied from the documentation):
{
"swagger": "2.0",
"info": {
"description": "desc",
"title": "TestAPI",
"version": "1.0"
},
"schemes": [
"https"
],
"paths": {
"/": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "test",
"headers": {
"Content-type": {
"type": "string"
}
}
}
},
"x-amazon-apigateway-integration" : {
"type" : "aws",
"uri" : "[REDACTED]",
"credentials" : "[REDACTED]",
"httpMethod" : "POST",
"requestTemplates" : {
"application/json" : "#set ($root=$input.path('$')) { \"stage\": \"$root.name\", \"user-id\": \"$root.key\" }"
},
"requestParameters" : {
"integration.request.querystring.stage" : "method.request.querystring.version",
"integration.request.querystring.provider" : "method.request.querystring.vendor"
},
"responses" : {
"2\\d{2}" : {
"statusCode" : "200",
"responseParameters" : {
"method.response.header.requestId" : "integration.response.header.cid"
},
"responseTemplates" : {
"application/json" : "#set ($root=$input.path('$')) { \"stage\": \"$root.name\", \"user-id\": \"$root.key\" }"
}
},
"302" : {
"statusCode" : "302",
"responseParameters" : {
"method.response.header.Location" : "integration.response.body.redirect.url"
}
},
"default" : {
"statusCode" : "400",
"responseParameters" : {
"method.response.header.test-method-response-header" : "'static value'"
}
}
}
}
}
}
}
}
But the problem is that
aws apigateway import-rest-api --body 'file://deploy/api.json' --region eu-west-1
Outputs the following:
An error occurred (BadRequestException) when calling the ImportRestApi operation: Errors found during import:
Unable to put integration on 'GET' for resource at path '/': Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression parameter specified: method.request.querystring.version]
That part is taken directly from the documentation, so this is really confusing to me. Any ideas what to do? Documentation seems lacking in many ways, so it is hard to solve many problems with it.
Have you tried defining version and vendor as parameters to the method?
{
"swagger": "2.0",
"info": {
"description": "desc",
"title": "TestAPI",
"version": "1.0"
},
"schemes": [
"https"
],
"paths": {
"/": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters" : [
{
"name" : "version",
"in" : "query",
"required" : true,
"type" : "string"
"description" : "The version requested"
},
{
"name" : "vendor",
"in" : "query",
"required" : true,
"type" : "string"
"description" : "The vendor being queried"
}
],
"responses": {
"200": {
"description": "test",
"headers": {
"Content-type": {
"type": "string"
}
}
}
},
"x-amazon-apigateway-integration" : {
"type" : "aws",
"uri" : "[REDACTED]",
"credentials" : "[REDACTED]",
"httpMethod" : "POST",
"requestTemplates" : {
"application/json" : "#set ($root=$input.path('$')) { \"stage\": \"$root.name\", \"user-id\": \"$root.key\" }"
},
"requestParameters" : {
"integration.request.querystring.stage" : "method.request.querystring.version",
"integration.request.querystring.provider" : "method.request.querystring.vendor"
},
"responses" : {
"2\\d{2}" : {
"statusCode" : "200",
"responseParameters" : {
"method.response.header.requestId" : "integration.response.header.cid"
},
"responseTemplates" : {
"application/json" : "#set ($root=$input.path('$')) { \"stage\": \"$root.name\", \"user-id\": \"$root.key\" }"
}
},
"302" : {
"statusCode" : "302",
"responseParameters" : {
"method.response.header.Location" : "integration.response.body.redirect.url"
}
},
"default" : {
"statusCode" : "400",
"responseParameters" : {
"method.response.header.test-method-response-header" : "'static value'"
}
}
}
}
}
}
}
}
API Gateway requires method request parameters to be defined before being referenced

Find one key and value form whole mongodb object

I have records in mongodb as below
{
"_id" : "aqDHbgueSaXFWRzys",
"i18n" : {
"fa" : {
"testimonial" : {
"content" : {
"1" : {
"testimonialTitle" : {
"newValue" : "11111111",
"isVerified" : false
},
"testimonialDescription" : {
"newValue" : "11111111",
"isVerified" : false
}
}
}
},
"companyInfo" : {
"companyName" : "red Fr"
}
},
"tr" : {
"companyInfo" : {
"companyName" : "JD Company tr"
}
},
"ar" : {
"companyInfo" : {
"companyName" : "ER JD Company"
}
},
"ru" : {
"companyInfo" : {
"companyName" : "JD Company Rs"
}
}
},
"updateDate" : ISODate("2016-08-08T09:34:26.824Z"),
"testimonial" : {
"content" : {
"0" : {
"testimonialTitle" : {
"newValue" : "Testimonial Title 45465 1",
"isVerified" : true
},
"testimonialDescription" : {
"newValue" : "Testimonial Text gfh dfghdfgh 1",
"isVerified" : true
}
},
"1" : {
"described" : {
"newValue" : "2",
"isVerified" : true
},
"communication" : {
"newValue" : "2",
"isVerified" : true
},
"shipingTime" : {
"newValue" : "3",
"isVerified" : true
},
"shipingHandling" : {
"newValue" : "3",
"isVerified" : true
},
"testimonialImageUrl" : {
"newValue" : "",
"isVerified" : true
},
"testimonialTitle" : {
"newValue" : "jayeshjayeshjayesh",
"isVerified" : true,
},
"testimonialDescription" : {
"newValue" : "jayeshjayeshjayeshjayeshjayeshjayesh",
"isVerified" : true
},
"testimonialDate" : {
"newValue" : ISODate("2016-08-24T18:30:00.000Z"),
"isVerified" : true
}
}
}
},
"companyInfo" : {
"companyName" : "Shanghai GEG Garment Co.,Ltd"
},
"storeName" : "sunny1"
}
In above object you can find isVerified many times. So I want to find that If any isVerified:true is remaining or not

Elasticsearch index operation fails on complex object

I am indexing a data stream to Elasticsearch and I cannot figure out how to normalize incoming data to make it index without error. I have a mapping type "getdatavalues" which is a meta-data query. This meta-data query can return very different looking responses but I'm not seeing the difference. The error I get:
{"index":{"_index":"ens_event-2016.03.11","_type":"getdatavalues","_id":"865800029798177_2016_03_11_03_18_12_100037","status":400,"error":"MapperParsingException[object mapping for [getdatavalues] tried to parse field [output] as object, but got EOF, has a concrete value been provided to it?]"}}
when performing:
curl -XPUT 'http://192.168.99.100:80/es/ens_event-2016.03.11/getdatavalues/865800029798177_2016_03_11_03_18_12_100037' -d '{
"type": "getDataValues",
"input": {
"deviceID": {
"IMEI": "865800029798177",
"serial-number": "64180258"
},
"handle": 644,
"exprCode": "200000010300140000080001005f00a700000000000000",
"noRollHandle": "478669308-578452",
"transactionID": 290
},
"timestamp": "2016-03-11T03:18:12.000Z",
"handle": 644,
"output": {
"noRollPubSessHandle": "478669308-578740",
"publishSessHandle": 1195,
"status": true,
"matchFilter": {
"prefix": "publicExpr.operatorDefined.commercialIdentifier.FoodSvcs.Restaurant.\"A&C Kabul Curry\".\"Rooster Street\"",
"argValues": {
"event": "InternationalEvent",
"hasEvent": "anyEvent"
}
},
"transactionID": 290,
"validFor": 50
}
}'
Here's what Elasticsearch has for the mapping:
"getdatavalues" : {
"dynamic_templates" : [ {
"strings" : {
"mapping" : {
"index" : "not_analyzed",
"type" : "string"
},
"match_mapping_type" : "string"
}
} ],
"properties" : {
"handle" : {
"type" : "long"
},
"input" : {
"properties" : {
"deviceID" : {
"properties" : {
"IMEI" : {
"type" : "string",
"index" : "not_analyzed"
},
"serial-number" : {
"type" : "string",
"index" : "not_analyzed"
}
}
},
"exprCode" : {
"type" : "string",
"index" : "not_analyzed"
},
"handle" : {
"type" : "long"
},
"noRollHandle" : {
"type" : "string",
"index" : "not_analyzed"
},
"serviceVersion" : {
"type" : "string",
"index" : "not_analyzed"
},
"transactionID" : {
"type" : "long"
}
}
},
"output" : {
"properties" : {
"matchFilter" : {
"properties" : {
"argValues" : {
"properties" : {
"Interests" : {
"type" : "object"
},
"MerchantId" : {
"type" : "string",
"index" : "not_analyzed"
},
"Queue" : {
"type" : "string",
"index" : "not_analyzed"
},
"Vibe" : {
"type" : "string",
"index" : "not_analyzed"
},
"event" : {
"properties" : {
"event" : {
"type" : "string",
"index" : "not_analyzed"
},
"hasEvent" : {
"type" : "string",
"index" : "not_analyzed"
}
}
},
"hasEvent" : {
"type" : "string",
"index" : "not_analyzed"
},
"interests" : {
"type" : "string",
"index" : "not_analyzed"
}
}
},
"prefix" : {
"type" : "string",
"index" : "not_analyzed"
},
"transactionID" : {
"type" : "long"
},
"validFor" : {
"type" : "long"
}
}
},
"noRollPubSessHandle" : {
"type" : "string",
"index" : "not_analyzed"
},
"publishSessHandle" : {
"type" : "long"
},
"status" : {
"type" : "boolean"
},
"transactionID" : {
"type" : "long"
},
"validFor" : {
"type" : "long"
}
}
},
"timestamp" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"type" : {
"type" : "string",
"index" : "not_analyzed"
}
}
},
Looks like the argValues object doesn't quite agree with your mapping:
"argValues": {
"event": "InternationalEvent",
"hasEvent": "anyEvent"
}
Either this:
"argValues": {
"event": {
"event": "InternationalEvent"
},
"hasEvent": "anyEvent"
}
Or this:
"argValues": {
"event": {
"event": "InternationalEvent"
"hasEvent": "anyEvent"
},
}
Would both seem to be valid.