Skip to content

Contentstack-Solutions/webhooklistener-generatePermanentURL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webhook Listener

A Python Lambda Webhook Listener - Generates a permanent URL on created assets. See doc on Generating a Permanent URL: https://www.contentstack.com/docs/developers/apis/content-management-api/#generate-permanent-asset-url

This repository is not officially supported by Contentstack

Use the issue tracker in this repository or contact oskar.eiriksson@contentstack.com

Note: This code can only be executed once on every asset. The permanent URL cannot be changed after generating it.

Developed using Python 3.9.

Step by step:

1. Create a Lambda function and an API Gateway in AWS Lambda. Based on these documentation articles:

2. Environmental variables needed:

  • CS_APIKEY -> API Key of the Stack.
  • CS_MANAGEMENTTOKEN -> Management Token on the stack with write access
  • CS_REGION -> Either NA (North America Region) or EU (Europe Region)
  • CS_SECRET -> Defined secret - Used as a custom header in the webhook settings in Contentstack.
    • Note: The header value in Contentstack (secret) needs to match the value of this environmental variable.

You can define those environmental variables in your OS and run testLambda.py. You will need to define them in the Lambda configuration for it to work in a real world scenario.

3. It's good to update both code and configuration in Lambda with awscli.

  • To update code via awscli: * install pip module into a subdirectory like this:
    • pip install --target ./package requests. * Add all files and folders from the package folder (not the package folder itself) into a zip file with the lambda_function.py, along with the config and cma folders. Finally upload the zip file to Lambda like this:
    • aws lambda update-function-code --function-name <Name of your Lambda function> --zip-file fileb://function.zip

4. Define a webhook in Contentstack.

  • Give it a descriptive name
  • The URL should be the URL generated by the API Gateway in step 1.
  • Leave authentication information empty
  • Define a custom header secret - Give it the same value as the CS_SECRET variable in step 2.
  • Define the condition for the webhook: When Any -> Asset is Created.
  • Make sure the webhook is not set to concise and is enabled (The two checkmarks at the bottom).

About

A Python AWS Lambda Webhook listener that generates a permanent URL when an asset is created in Contentstack.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages