Deploying AWS agent in AWS Lambda functions
Deploy the AWS Agent developed for the Amazon API Gateway as AWS Lambda functions.
About this task
You can configure a Lambda function, Heartbeatshandler (for retrieving Amazon API Gateway’s health status and sending it to Federated API management) that uses the Lambda console. Follow the same procedure to create and configure the Lambda function for retrieving APIs, and Metrics. For details about the class and method names that are required for configuring Lambda Functions, see Handler field values.
Before you begin
- Downloaded the artifact corresponding to the AWS API Gateway Lambda function agent component from the Download resources page.
- Federated API management, version 11.1.7.
- Verified whether Amazon API Gateway and federated API management for which you want to establish connectivity that uses the agent are up and running.
- Created an IAM user in AWS with the following roles assigned
- AmazonAPIGatewayAdministrator
- AWSCloudTrail_ReadOnlyAccess
- CloudWatchReadOnlyAccess
- AWSLambdaBasicExecutionRole. For more details, see Lambda Execution Role.
Creating a Lambda function, Heartbeatshandler
- Open AWS Lambda Service.
By default, the Functions page of the AWS Lambda console opens.
- Click Create Function.
- Select the Author from scratch.
- Edit the following details as required in the Basic information section:
- Function name. Enter a name that describes the purpose of your function.
For example, Heartbeatshandler.
- Runtime. Choose Java 17 as the language to write your function.
- Architecture. Choose x86_64 as the instruction set architecture for your function code.
- Click Create Function.
Lambda creates a function, Heartbeatshandler, which is listed under Functions.
Note: Make sure that you have created the Lambda function in the same region where the Amazon API Gateway is hosted - Function name. Enter a name that describes the purpose of your function.
Configuring a Lambda Layer
A Lambda layer is a compressed file archive that contains the dependencies for the agent to run. Uploading the dependencies in the Layer reduces the size of the deployment package, separates core function logic from dependencies, and allows to share the dependencies across multiple functions.
- Click Additional resources > Layers from the left navigation page.
- Choose Create Layer.
- Edit the following details as required:
- Name. Enter a Layer name.
For example, AWSLambdaLayer
- Upload the dependencies Jar.
Choose Upload a compressed file >upload and select the lambda-layer.zip, which includes all dependencies to run the Lambda function.
- Compatible architectures. Choose x86_64 as the compatible architecture.
- Compatible runtimes. Choose Java 17.
- Click Create.
The Lambda layer, AWSLambdaLayer is created, which can be configured in all the Lambda functions.
- Name. Enter a Layer name.
Specify the required configurations for the Lambda function, Heartbeatshandler to run
- Click Functions from the left navigation page.
- Choose the Heartbeatshandler function.
- Select the Code.
- Select Layer and click Add a Layer.
- Choose the Layer source as Custom Layers.
- Select AWSLambdaLayer in the Custom Layers drop down menu.
- Choose the Version as 1.
- Click Add.
AWSLambdaLayer is added to the Heartbeatshandler function.
Upload the Heartbeat Jar- Select Code source >Upload and select the send-heartbeat.jar.
- Click Save.
The send-heartbeat.jar is uploaded. You can verify the package size under code properties to know whether the Jar is uploaded.
- Click Edit.
- Handler. Specify the Class and Method name from the send-heartbeat.jar, which triggers when the
Heartbeatshandler function is invoked. By default,
com.example.Function::Handleis populated in the field.Here, com.example.Function must be replaced with com.webmethods.api.controlplane.awslambda.heartbeat.FunctionHandler::handle Event.
- Click Save.
The Runtime settings are configured.
Environment variables include Amazon API Gateway, agent, runtime, and federated API management configurations. These configurations are required to connect Amazon API Gateway with federated API management.
-
- Click Configuration > Environment variables.
- Click Edit.
- Add the Environment variables and their values. For details about the variables and recommended value, see Lambda Functions - Environment variables.
Specify the Amazon EventBridge Scheduler for the Heartbeatshandler function
To set a trigger point for the Heartbeatshandler Function, use the Amazon EventBridge Scheduler service. To create an EventBridge Scheduler, you can either click Add trigger in the Function overview section of your Lambda function and choose EventBridge (CloudWatch Events) from the dropdown or use AWS EventBridge Scheduler service from the AWS services console.
The following procedure describes the steps to set a trigger that uses the AWS EventBridge Scheduler service from the AWS services console. Follow from the Specify the required cHeartbeat configurations for Lambda function, Heartbeatshandler to run step if you want to add a trigger from within your Lambda function:
- Search for AWS EventBridge Scheduler service in the Search bar in the AWS services console.
- Choose EventBridge Rule in the right page.
- Click Create Rule .
The Define rule detail page appears.
- Specify the name of the rule.
For example, HeartbeatSyncInterval.
- Select the Rule Type as Schedule.
-
Click Next.
The Define schedule page appears.
- Choose the Schedule pattern as A schedule that runs at a regular rate such as every 10 minutes.
- Rate expression. Enter a value and the unit of time to run the schedule.For example, Value: 1, Unit: MinutesNote: Make sure that the synchronization time interval values exactly match those in the environment variables. Specify the time intervals only in minutes, hours, or days; seconds are not allowed. For example, if API_CP_HEARTBEAT_SEND_INTERVAL is 60 seconds, set the Amazon EventBridge service Rate expression to 1 minute. Configure the Environment variables for the function to make sure that the time intervals in seconds can be easily converted to minutes without any decimal values.
- Click Next.
The Select target(s) page appears.
- Select a target. Choose a Lambda function to invoke when the schedule is triggered.
- Function. Choose the Lambda function name. For example, Heartbeatshandler
- Click Next.
The Configure tags – optional page appears.
- Click Next.
The Review and create page appears.
Click Create rule.
The created rule gets associated with the Heartbeatshandler Lambda function and is enabled automatically.
To verify whether the EventBridge Scheduler is associated, open Heartbeatshandler Lambda function, click Configuration tab > Triggers, and the EventBridge rule is displayed with the Rule state as ENABLED.
As specified in the EventBridge rule, every 1 minute, the EventBridge triggers the Lambda function, Heartbeatshandler, and the application logic within the Lambda function gets executed. That is, the agent retrieves Amazon API Gateway’s heartbeats(status) and sends it to federated API management.- Verify if the runtime is registered with federated API management
and whether the heartbeats (status) are sent to federated API management successfully.
- Open the federated API management application.
- On the Catalog page, click the Runtimes.
- Check if the runtime is registered with federated API management by verifying whether the AZURE_API_MANAGEMENT_SERVICE_NAME (specified in the .env file) is listed. If the runtime is listed, it indicates that the runtime is successfully registered with the federated API management.
-
Check whether the runtime's health status is sent to federated API management by verifying the status of that corresponding runtime in the Status column. The status appears green only if the runtime is up and the heartbeats (status) are received successfully by federated API management.
- Check whether the APIs are published from the runtime to federated API management by selecting Details from Action menu of the corresponding runtime for which, you want to verify whether its APIs are published to federated API management.
-
Click Relations tab.
A list of all the APIs associated with the runtime appears. You can also view the runtimes and its associated APIs in the APIs tab of the Catalog page.
- Check if the API metrics are synchronized from the runtime to federated API management by
clicking the
icon under the Action column corresponding to the runtime for which, you want to verify if the metrics are published to federated API management.
- Click Insights tab.
The Runtime-specific monitor page renders the metrics of that runtime pertaining to a specified time interval. It lists the metrics such as Transactions, Error rate, Availability, Response time . For details, see Monitoring performance of runtimes in federated API management.