I need to enable Custom Access Logging in API Gateway. The cloudformation is written in yaml. But for the format of the custom logs it is in json, xml such formats but nothing is mentioned how to set format of access log in yaml. Does anyone knows how to do it?
From the CloudFormation user guide, the Format attribute requires your input to be String.
DestinationArn: String
Format: String
For example:
DestinationArn: !Sub ${ApiAccessLogGroup.Arn}
Format: "{ 'requestId':'$context.requestId', 'ip': '$context.identity.sourceIp', 'caller':'$context.identity.caller', 'user':'$context.identity.user','requestTime':'$context.requestTime', 'xrayTraceId':'$context.xrayTraceId', 'wafResponseCode':'$context.wafResponseCode', 'httpMethod':'$context.httpMethod','resourcePath':'$context.resourcePath', 'status':'$context.status','protocol':'$context.protocol', 'responseLength':'$context.responseLength' }"
To simplify your String or make it looks better, please use !Sub as this post.
Related
I have an OpenAPI 3.0.1 file and conforming to the standard it contains some examples responses for endpoints. Now since some of the parameters in the response are set to be nullable there are some examples which look as follows:
examples:
account_not_verified:
value:
eamil: 'test#example.com'
verification: '0'
name: null
Since the name parameters is set up like this:
name:
type: string
nullable: true
I would assume that having a null value in the example response is valid by the open api standard. When I put this into the Swagger Editor is does not show any errors or warnings. But as soon as I include the OpenAPI file into my sam template to be used to configure an HTTP API Gateway like so:
ApiGateway:
Type: AWS::Serverless::HttpApi
Properties:
StageName: !Ref Stage
FailOnWarnings: true
DefinitionBody:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: ./oapi.yml
Cloud formation gives me the following error:
[/Resources/ApiGateway/Type/Body/paths/***/content/application/json/examples/ch_account_not_verified/value/name] 'null' values are not allowed in templates
Is there any way to allow this null value to exist in the example response or do I have to use some different method to indicate the null value in the example?
So with some trial and error, I was able to define it to allow strings and nulls, at least for a SAM template RequestBody. I am assuming API gateway uses JSON validation under the sheets, so if you define this in JSONSchema , for something like AWS power-tools validation, for example:
"properties": {
"spouse_first_name": {
"$id": "#/properties/spouse_first_name",
"type": ["string", "null"],
"title": "The spouse_first_name",
"maxLength": 100
}
}
Then the equivalent syntax in SAM template YAML would be:
MyRequestModel:
type: object
properties:
spouse_first_name:
type: string, null
maxLength: 100
I just tested this and it seems to allow both strings and nulls.
In the case of body validation, Don't forget to add 'ValidateBody: true' in your SAM template to force API gateway to validate your payload:
RequestModel:
Model: MyRequestModel
ValidateBody: true
I realize this is not an apples to apples answer, but the take away is that you should be able to define it in comma separated values in YAML
I am trying to add Lambda#Edge association in cloudfront using cloudformation. As per aws docs they had only two fields like EventType and LambdaFunctionARN . But i want to add IncludeBody in cloudformation so that my Lambda#Edge will read the body of the request . When i try to add IncludeBody in cloudformation it is saying error like invalid property.
"LambdaFunctionAssociations":
[
{
"EventType": "origin-response",
"IncludeBody":"true" -- Invalid property error
"LambdaFunctionARN": "arn:aws:lambda:us-east-1:134952096518:function:LambdaEdge:1"
}
]
So, can't i add this through cloudformation . Or i need to do it manually from console ?
Any help is appreciated
Thanks
According to AWS docs, there is an IncludeBody property for LambdaFunctionAssociations. But they also say that it can only be used for "viewer-request" and "origin-request" EventTypes. It looks like you have an "origin-response" EventType, so IncludeBody shouldn't be applicable here. Yet, in the official CloudFormation reference, there is no mention of IncludeBody. So I can only guess that CloudFormation is missing this feature right now and you may only be able to set IncludeBody via the API.
I can find formats for this using the CLI
aws sns publish --topic-arn arn:aws:sns:us-west-2:111111111111:test
--message "Testing the CLI"
--subject "From the CLI" --message-attributes "{\"somename\":
{\"DataType\":\"String\",\"StringValue\":\"somevalue\"}}"
But what I can't find (or figure out) is how to do this from the Integration Request on an API Gateway.
I believe it needs to be done as Query Parameters of the Integration Request, but the syntax is not the same as adding Message Attributes for SQS. I tested that by using a parameter naming notation along the lines of this example:
MessageBody=This+is+a+test+message
MessageAttribute.1.Name=test_attribute_name_1
MessageAttribute.1.Value.StringValue=test_attribute_value_1
MessageAttribute.1.Value.DataType=String
I also tried:
MessageAttributes '{"store":{"DataType":"String","StringValue":"example_corp"}}'
So far can't get it working, any help is much appreciated.
After thorough research into the AWS docs, I found that there is no accurate documentation of setting up SNS Publish MessageAttributes in an API Gateway Resource Method as URL Query String Parameters.
Based on the partial syntax example they give here: https://docs.aws.amazon.com/sns/latest/api/API_Publish.html, I was then able to throw things at it until something stuck.
This is the proper dot notation syntax and parameters you need to use:
MessageAttributes.entry.1.Name = "Attribute1"
MessageAttributes.entry.1.Value.DataType = 'String'
MessageAttributes.entry.1.Value.StringValue = 'Test'
Where "Name" and "DataType" are required.
Cheers!
When setting up URL Query String Parameters in the Integration Request part of an API method, it looks like I have the following options
reference a value from method.request.{path|querystring|header}.{var-name}
use a fixed single-quoted string
Even though API Gateway allows complex mappings on the body via VTL, it looks like querystring, header, and path variables do not have this option.
The specific use case I have is I want to populate the prefix query parameter for a call to S3's REST API with something like: 'read'+method.request.path.folder, so all GET requests start under a prefix (without the user having to specify that prefix).
Is there a way for me to achieve this goal using API Gateway?
Good day everyone,
I need to pass the value of a write-back field from docusign document to Salesforce.
Can you kindly provide an example of a string specifying the properties of MergeFieldXml like configuration type, path, etc.
According to Docusign SOAP API (https://www.docusign.net/api/3.0/dsapi.asmx?op=RequestEnvelopeWithDocumentFields) the MergeField property is passed as string:
<MergeFieldXml>string</MergeFieldXml>
At the same time the string should contain properties like:
Configuration type: salesforce (always)
path: objetc.field
row: record id
writeback: true if the data should be posted to salesforce.
My try does not work showing 'Web service callout failed: WebService returned a SOAP Fault: A Mergefield value for a Tab could not be retrieved. faultcode=soap:Client faultactor=missing in Web.Config
Row Number: 1196'
tab19.MergeFieldXml = '<configurationType>salesforce</configurationType><path>contact.Question_1_Agreement__c</path><writeback>true</writeback><allowSenderToEdit>false</allowSenderToEdit>';
If using REST API this would look as follows:
"mergeField": {
"configurationType":"Salesforce",
"path":"contact.Question_1_Agreement__c",
"writeback":"true",
"allowSenderToEdit":"true",
}
According to SOAP API documentation (https://www.docusign.com/p/APIGuide/APIGuide.htm#Sending Group/Tab.htm%3FTocPath%3DDocuSign%2520Service%2520API%2520Information%7CSending%2520Function%2520Group%7CCreateAndSendEnvelope%2520and%2520CreateEnvelope%7CTab%7C_____0)
MergeFieldXml is 'reserved for future'.
Does it mean it is not implemented yet?
how do we pass values back to salesforce using SOAP MergeFieldXml?
Or there may be some other way to accomplish this?
Thank you for any advise.