InPart 3, we described the procedure for using CloudWorks APIs.

But the main question would be—how can we use them? Indeed, we can find that having a dedicated screen in Anaplan itself is already a major step forward. And it surely addresses most of the future needs.

Nevertheless, in our strive to open our platform as much as possible, we wanted to provide an example of how to use those APIs in a practical situation.

Here's our business case for this practical example:

The business would like to have the import triggered following an ad-hoc event and not via a scheduler. In that case, there is no current way to do so with the CloudWorks native features. But thanks to the APIs, we will show here a way to trigger an import after uploading a file in an S3 bucket.

Before Starting

First, you might be wondering why those new APIs matter. This use case could indeed have been addressed by using Anaplan bulk APIs. But a quick look at the following schema will convince you of the reason why those new APIs are handy, at least for quick developments.

annejulie_0-1614014480615.png

With the bulk APIs, the developer would have had to handle a lot more topics (Anaplan's API, AWS S3 APIs, and the links between those two platforms). Even though it can be done, it adds more complexity, and moreover, it adds more subjects that can potentially go wrong. Additional complexity is also to get the status at each different step, making this development closer to an actual software.

annejulie_1-1614014480628.png

On the other hand, with CloudWorks APIs as shown above, the flow is more straightforward (the file, the bucket are already specified in the integration) and Anaplan will primarily support what will happen when the job will be executed.

In our example, we will trigger the integration after uploading a particular file in a dedicated bucket. This bucket will be a different one than the one set up in the CloudWork connection.

Note:We could also have used the same bucket. But that can also illustrate some options when IT would like to implement their own triggers.

Let's begin!

Step 1: Ensure all elements have been created

You will need to have set up a working integration in CloudWorks before starting.

This means:

  • A working action (imports, exports or processes) in Anaplan
  • 克劳沃连接
  • A working integration using the latter in CloudWorks

Step 2: Create Secrets

We will store that information in that AWS keeper place and use them when authentication to Anaplan will be required.

annejulie_2-1614014480642.png

In IAM console, create a strategy that will be used to get the secret values.

annejulie_3-1614014480660.png

Step 3: Create a Bucket

We could use the same bucket as the one that was used in CloudWorks, but it's not mandatory.

Step 4: Create a Lambda Function

With the code available here, we already prepared the minimum package to execute an integration.
This is the contents of the "LambdaPythonCodes.zip" file that you can download from that article.

  1. AnaplanAPI.py
  2. lambda_function.py
  3. RetrievalSecrets.py

In the python code calledAnaplanAPI.py, there are two classes.

  1. AnaplanAuthHandler: In the code, we take care of the authentication part (basic authentication for now). We will mainly issue the tokenValue needed to perform subsequent APIs requests.
  2. AnaplanCloudWorks: In that code, we will have functions that will help to gather all information needed to trigger an integration based on the name of a particular integration.

"RetrievalSecrets.py" helps to get values from the secret created in Step 1.

"lambda_function.py" is the code that will proceed to the execution of the integration.

In that latter file, you can see that the integration name and the secrets details are hard-coded and they will need to be adapted to your situation:

christophe_keom_0-1634193953441.png

Info:We created a "Layer" that encompasses the requests package. We could have used boto3 requests version but requests package looks to be more up-to-date.

In order to know how to create a layer, follow the instructions in this AWSpageand use the "python.zip" file as such attached to that article.

Step 5: Set Up the Permissions

Click on "Permissions" and on the role name link.

annejulie_4-1614014480668.png


On the following screen, click on "Attach policies" and select the policy you've created in Step 2.

现在,再次单击“附加策略”和寻找the secret policy you created in Step 1.

annejulie_5-1614014480680.png

Now, you should have three lines:

annejulie_6-1614014480695.png

Step 6: Test the Lambda

You can create a test event and check if the lambda already does what it is supposed to do, without the event.

Just click on Test, create a test event (without amending anything), and click on Save.

A successful test should be as followed:

annejulie_7-1614014480712.png

Step 7: Add the Trigger Event

The final step is to set up the trigger event, which is a simple upload of a file in a particular bucket. As we don't want to trigger an integration for every file that could be uploaded to the bucket, we will use a prefix.

annejulie_8-1614014480725.png

To trigger the lambda, you'll need to upload a simple file with a prefix "veloce-".

我们现在可以测试通过ploading such a file:

annejulie_9-1614014480739.png

Go back to your lambda and if all is successful, you should see CloudWatch events similar to the following one:

annejulie_10-1614014480770.png

You now have an integration from AWS S3 to Anaplan that can be conditionally triggered by an event!

The code used in that document is available (LambdaPythonCodes.zip); feel free to download it and use it.

Found this content useful? Got feedback?Let us know in the comments below!

The content in this article has not been evaluated for all Anaplan implementations and may not be recommended for your specific situation.
Please consult your internal administrators prior to applying any of the ideas or steps in this article.
Comments

Hi,

Thx for the tutorial.

I think some parts are missing:

- How to configure the lambda (we have to specify the name of the Anaplan integration)

- Where to specify the Secrets hosted region

- Anaplan Integration must exists prior to the lambda integration

Best,

EN

Hi EN,

Thank you for your very useful feedback.

I've amended the articles and the codes as suggested.

Have a great day,

Christophe K.