AWS Lambda

Use the AWS Lambda policy to invoke an AWS Lambda function.

Example of an AWS Lambda policy.

kind: InvokeAWSLambdaFunction
apiVersion: api.webmethods.io/beta
metadata:
  name: AWSLambdaExtension
  version: 1
  namespace: sample
  tags:
    - AWS
    - Lambda
    - Extension
    - Policy
spec:
  enabled: true
  condition: (${request.httpMethod} equals POST) or (${request.headers.name} notEquals ${request.payload.jsonPath[$.customer.name]})
   # other operators include Equals, Equals ignore case, Not equals, Not equals ignore case, Contains, Not Contains, Exists, Not Exists, IP Range, Greater Than, Lesser Than
  lambdaConfig:
    functionName: test
    async: true #invocation type - request-response ( false)  or event ( true )
    alias: test
    clientConfig:
      socketTimeout: 1000
      connectionTimeout: 1000
      requestTimeout: 1000
      connectionExpirationTime: 1000
      maxConnectionIdleTime: 1000
      clientExecutionTimeout: 1000
      retryOnErrorCount: 1
      enableThrottledRetries: true
      maxClientRetries: 1
      tcpSendBufferSizeHint: 10
      tcpReceiveBufferSizeHint: 10
      enableGzip: true
      enableExpectContinue: true
      enableHostPrefixInjection: true
      enableKeepAlive: true
      enableResponseMetadataCache: true
      responseMetadataCacheSize: 10kb
      signatureAlgorithm: test
  request_processing:
    transformations:
    set:
      - key: ${request.headers.h2}
        value: test4
      - key: ${request.query.q2}
        value: ${request.payload.jsonPath[$.customer.name]}
    setPayload:
      content-types:
        - application/json: |
                      {"empid" : "1"}
        - application/xml: | 
                      <a>a<a>
        - text/plain: |
                    sample text
      default-ContentType: application/json
      xsl:
        - feature:
            - name: test
              value: value
          $path: ./a/a.xsl
          content: sdsd
    remove:
  response_processing:
    transformations:
    set:
      - key: ${request.headers.h2}
        value: test4
      - key: ${request.query.q2}
        value: ${request.payload.jsonPath[$.customer.name]}
    copyEntireResponse: true
    abortAPIExecutionForFailure: true 
  namespaces:
      - prefix: ps1
        URI: http://test.com
      - prefix: ps2
        URI: http://test2.com
       
As part of the AWS Lambda configuration, you can specify:
Type Description
kind InvokeAWSLambdaFunction. Defines the type of policy that is being configured.
apiVersion Denotes the version of the API in use.
metadata Denotes the metadata or details of the asset type.
It covers this metadata:
  • name. Name of the policy.
  • version. Version of the policy.
  • namespace. Namespace identifier for the policy.
  • tags. The tags associated with the policy. Use the following tags to tag the AWS Lambda policy:
    • AWS
    • Lambda
    • Extension
    • Policy
spec
You can configure the following policy properties:
  • enabled. Specifies whether the policy is active. Set the value to true to enable the policy, and set it to false to disable the policy.
  • condition. Conditions are used to specify when the policy is run. You can add multiple conditions with logical operators. Provide the condition in the format: {set} operator {value} condition {set} operator {value}

    You can use the following conditions:

    • Transform the requests that comply with all the configured conditions in the code view by using and, or in the form view by selecting the AND option.
    • Transform the requests that comply with any one configured condition in the code view by using or, or in the form view by selecting the OR option.

    You can use the following operators in the code view and in the form view by using the Add condition button, which is optional.

    • Equals
    • Equals ignore case
    • Not equals
    • Not equals ignore case
    • Contains
    • Not Contains
    • Exists
    • Not Exists
    • IP Range
    • Greater Than
    • Lesser Than
  • Specify the Lambda configurations in the code view by using lambdaConfig, or in the form view from AWS Lambda tab, using Function name.
    • Choose to call this function asynchronously in the code view by using async. Set the value to true to enable asynchronous function, and set it to false to disable it. In the form view, by selecting the AND option.
    • Specify the version alias for Lambda in the code view by using alias, or in the form view under the AWS alias label.
    • Add the client configuration in the code view by using clientConfig, or in the form view using the Add client configuration button.

      You can configure the following fields:
      • SocketTimeout
      • connectionTimeout
      • requestTimeout
      • connectionExpirationTime
      • maxConnectionIdleTime
      • clientExecutionTimeout
      • retryOnErrorCount
      • enableThrottledRetries
      • maxClientRetries
      • tcpSendBufferSizeHint
      • tcpReceiveBufferSizeHint
      • enableGzip
      • enableExpectContinue
      • enableHostPrefixInjection
      • enableKeepAlive
      • enableResponseMetadataCache
      • responseMetadataCacheSize
      • signatureAlgorithm
  • Specify the request processing parameters in the code view by using request_processing, or in the form view using the Request processing section.

    You can configure the following transformation fields for both setPayload and remove functions:

    • Set the payload content type in the code view by using setPayload and in the form view, use the Payload type field, which is an optional step.

      Configure the content type in the code view using content-types, and in the form view use the Payload type field, which is an optional step. You can also choose to activate the Auto-format payload option.

      These are the content types that can be configured:
      • application/jsonin the code view and JSON in the form view. This is the default content type. On selecting this option, a code editor opens up for you to configure the content requirements.

      • application/xmlin the code view and XML in the form view. On selecting this, you get an option to upload an XML file.

      • text/plainin the code view and Text in the form view. On selecting this, you get a plain text box to configure the file.

    • Add or update a new header in the message configuration request in the code view by using set and configure the key and value.

      In the form view, use the Add header parameter button for this configuration where you can specify the Header name and Header value.

  • Specify the response processing parameters in the code view by using response_processing, or in the form view using the Response processing section.

    Configure the following details:
    • Complete response from the messaging extension is forwarded back to the client in the code view when you set the copyEntireResponse to true.

      In the form view, you can configure this by selecting the Copy entire response field, which is optional.

    • Specify if the API execution should be stopped in case of messaging extension invocation failure in the code view when you set the abortAPIExecutionForFailure to true.

      In the form view, you can configure this by selecting the Abort API execution in case of failure field, which is optional.

    • Click the button in the Transformation section to configure the response processing transformation.
    • In the code view, configure the set function and add the required details as key and value.

      In the form view, use the Add transformations button for this configuration where you can specify the Variable and Value, which are both optional fields.

  • Configure the metadata for the message configuration request in the code view by using namespaces and configure the prefix and URI.

    In the form view, use the Custom metadata extension section to configure the metadata. Click the Add namespace button for this configuration and specify the Namespace prefix and Namespace URL, which are both optional fields.