Giter Club home page Giter Club logo

fn-text2pdf-events's Introduction

Event driven function for converting text to PDF

This event driven function converts a text file to PDF. Once you drop a text file into an Oracle Cloud Infrastructure Object Storage Bucket and configure the appropriate trigger rule, the function will convert it into PDF and store the converted file (with a .pdf extension) in an output bucket specified by the user

  • The function written in Go and uses gofpdf for text to PDF conversion
  • Uses the OCI Go SDK to execute Object Storage read and write operations
  • A custom Dockerfile is used to build the function

Pre-requisites

Switch to correct context

  • fn use context <your context name>
  • Check using fn ls apps

Create application

fn create app text2pdf --annotation oracle.com/oci/subnetIds=<SUBNETS> --config TENANT_OCID=<TENANT_OCID> --config USER_OCID=<USER_OCID> --config FINGERPRINT=<FINGERPRINT> --config PASSPHRASE=<PASSPHRASE> --config REGION=<REGION> --config PRIVATE_KEY_NAME=<PRIVATE_KEY_NAME> --config OUTPUT_BUCKET=<OUTPUT_BUCKET>

the user credentials you provide here (using USER_OCID, FINGERPRINT etc. should have read and write access to the specified Object Storage bucket)

e.g.

fn create app text2pdf --annotation oracle.com/oci/subnetIds='["ocid1.subnet.oc1.phx.aaaaaaaaghmsma7mpqhqdhbgnby25u2zo4wqlrrcskvu7jg56dryxt3hgvka"]' --config TENANT_OCID=ocid1.tenancy.oc1..aaaaaaaaydrjm77otncda2xn7qtv7l3hqnd3zxn2u6siwdhniibwfv4wwhta --config USER_OCID=ocid1.user.oc1..aaaaaaaavz5efq7jwjjipbvm536plgylg7rfr53obvtghpi2vbg3qyrnrtfa --config FINGERPRINT=41:82:5f:44:ca:a1:2e:58:d2:63:6a:af:52:d5:3d:04 --config PASSPHRASE=4242 --config REGION=us-phoenix-1 --config PRIVATE_KEY_NAME=oci_private_key.pem --config OUTPUT_BUCKET=output-bucket

Check

fn inspect app text2pdf

Deploy the application

  • cd fn-text2pdf
  • fn -v deploy --app text2pdf --build-arg PRIVATE_KEY_NAME=<private_key_name> e.g. fn -v deploy --app text2pdf --build-arg PRIVATE_KEY_NAME=oci_private_key.pem

Create Events rule

Before that...

... find the function OCID (use the command below) and replace it in actions.json file

fn inspect fn text2pdf convert2pdf | jq '.id' | sed -e 's/^"//' -e 's/"$//'

Go ahead and create the rule...

oci --profile <oci-config-profile-name> cloud-events rule create --display-name <display-name> --is-enabled true --condition '{"eventType":"com.oraclecloud.objectstorage.object.create", "data": {"bucketName":"<bucket-name>"}}' --compartment-id <compartment-ocid> --actions file://<filename>.json

Replace <bucket-name> with the (input) Object Storage bucket name where you will upload the text file

e.g.

oci --profile devrel cloud-events rule create --display-name t2prule --is-enabled true --condition '{"eventType":"com.oraclecloud.objectstorage.object.create", "data": {"bucketName":"test"}}' --compartment-id ocid1.compartment.oc1..aaaaaaaaokbzj2jn3hf5kwdwqoxl2dq7u54p3tsmxrjd7s3uu7x23tkegiua --actions file://actions.json

Test

A sample text file (lorem.txt) has been provided to test the function. Upload this file to your object storage bucket and wait for the function to be triggered.

If successful, you should see a PDF (lorem.pdf) in the output Object Storage bucket specified by the user

fn-text2pdf-events's People

Contributors

abhirockzz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.