AWS Lambda

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

In IBM API Studio, this policy is identified by the kind InvokeAWSLambda.

Example of an AWS Lambda policy in code view.

kind: InvokeAWSLambda
apiVersion: api.ibm.com/v1
metadata:
  name: AWSLambdaExtension
  version: 1
  namespace: sample
spec:
  functionName: test
  qualifier: v1 # version of a function name
  invocationType: request-response #invocation type - request-response  or event 
  region: aws-us
  awsAuthType: 
    accessSecret: my-aws-secret 
  tlsConnectionProfile: my-aws-con-alias 
  input: inputMessage #optional 
  output: outputMessage #optional 
  clientConfig: 
    # Timeouts (in milliseconds)
    socketTimeout: 1000
    connectionTimeout: 1000
    requestTimeout: 1000
    clientExecutionTimeout: 1000
    clientRetryCount: 5
    connectionExpirationTimeout: 100
    enableExpectContinue: true
    enableGzip: true
    enableHostPrefixInjection: true
    maxConnectionIdleTime: 1000
    responseMetadataCacheSize: 128
    # Retry settings
    enableThrottledRetries: true
    # Connection settings
    enableKeepAlive: true
    enableResponseMetadataCache: true
    signatureAlgorithm: test
    tcpSendBufferSizeHint: 10
    tcpReceiveBufferSizeHint: 10
  extensions:
    dp-nano-gateway:
      apiVersion: api.ibm.com/v1
      spec:
        clientConfig:
          serverRetryCount: 3
    webm-gateway:
      apiVersion: api.ibm.com/v1 
      spec:
        condition: (${request.httpMethod} equals POST) or (${request.headers.name} notEquals ${request.payload.jsonPath[$.customer.name]})
        lambdaConfig:
          alias: test
        clientConfig:
          retryOnErrorCount: 1
        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
              defaultContentType: application/json
              xsl:
                - feature:
                    - name: http://javax.xml.XMLConstants/feature/secure-processing
                      value: true
                  $path: ./a/a.xsl
                  content: sdsd
            remove:
              - ${request.query.q1}
              - ${request.path}
          useIncomingHeaders: true
        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
       
For the InvokeAWSLambda policy kind, configure these specifications:
Code view Form view Description
condition Conditions

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 configure 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
lambdaConfig AWS Lambda
Configures the messaging system details such as connection, destination, and message format. Define these Lambda configurations after specifying the Function name:
  • Specify whether the Lambda function runs synchronously using RequestResponse or asynchronously using Event in the code view by using invocationType, or in the form view under the Invocation type label.
  • Specify the alias that points to a specific version of the Lambda function by using aliasin the code view, or in the form view under the AWS alias label.
  • Specify the version or alias of the Lambda function to invoke by using qualifier in the code view, or in the form view under the AWS qualifier label.
  • Specify the AWS region where the Lambda function is deployed by using region in the code view, or in the form view under the AWS region label.
  • Specify the secret key used with the access key to authenticate AWS API calls securely by using accessSecret in the code view, or in the form view under the AWS access secret label.
  • Specify the TLS profile that enforces secure communication with AWS services by using tlsConnectionProfile in the code view, or in the form view under the AWS TLS connection profile label.
  • Specify the JSON payload sent to the Lambda function for processing by using input in the code view, or in the form view under the AWS input label.
  • Specify the expected response returned by the Lambda function after execution by using output in the code view, or in the form view under the AWS output 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
    • clientExecutionTimeout
    • maxConnectionIdleTime
    • clientRetryCount
    • connectionExpirationTimeout
    • tcpSendBufferSizeHint
    • tcpReceiveBufferSizeHint
    • enableThrottledRetries
    • enableGzip
    • enableExpectContinue
    • enableHostPrefixInjection
    • enableKeepAlive
    • enableResponseMetadataCache
    • responseMetadataCacheSize
    • signatureAlgorithm
request_processing Request transformation

Specifies the request processing parameters.

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.

    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, query, or path parameter 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 variable button for this configuration where you can specify the Variable and Value.

  • Under xsl, you specify one or more transformation files that determine how the payload is modified before it’s sent or processed.

    In the form view, use the XSLT document section for this configuration.

    • $path. Specifies the location of the XSL transformation file. IBM API Studio reads the file from the given path and applies the defined transformation rules.
    • feature. Lists one or more transformation features as name-value pairs. The name must specify a valid feature, such as http://javax.xml.XMLConstants/feature/secure-processing, and the value must be set to true or false.

    You can include multiple XSL entries under setPayload to apply different transformations based on your configuration.

response_processing Response processing

Specifies the response processing parameters.

  • Specify the response processing parameters in the code view by using response_processing, or in the form view using the Response transformation 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 optional Copy entire response field.

    • 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 optional Abort API execution in case of failure field.

    • In the code view, configure the set function and add the required details as key and value.

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

namespaces Namespace

Configure the metadata for the message configuration request.

In the code view, under namespaces, configure the prefix and URI.

In the form view, use the Custom metadata extension tab 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.