Note: if you already have a Kubernetes cluster running in OCI, you don't need to create a separate VCN and Subnets (step #4 in the above documentation), instead you can use the OKE's VCN and subnets.
Download the installation script (Unix/Linux/MacOS)
curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh
If you are using Brew (on MacOS):
brew update && brew install fn
On Windows, download the `fn.exe` from GitHub Releases page.
docker login --username [username] --password [password] [region-key].ocir.io/[tenancy-namespace]
fn create context mushop-context --provider oracle
fn use context mushop-context
fn update context oracle.compartment-id [compartment-ocid]
api-url
endpoint (replace the [region] with an actual region name e.g.
us-phoenix-1
):
fn update context api-url https://functions.[region].oci.oraclecloud.com
registry
with an address of your Docker registry (e.g.
phx.ocir.io/my-tenancy/my-repo
)
fn update context registry [region-key].ocir.io/[tenancy-namespace]/[repo-name]
mushop@example.com
)
Note: if you have your own domain, you can enter a different address
(e.g. mushop@[yourdomain.com]
) and also configure SPF record for the sender. This involves
adding a DNS record to your domain. You can follow the instructions to configure SPF.
The SMTP credentails (host, port, username and password) and the approved sender email address will be provided to the function as configuration values later, so make sure you save these values somewhere.
mushop-app
) and the VCN and a
subnet in which to run the functions. Make sure you have your subnet OCID available before following the
steps below.
ocid1.subnet.oc1.iad...
with an actual subnet OCID):
fn create app mushop-app --annotation oracle.com/oci/subnetIds='["ocid1.subnet.oc1.iad...."]'
newsletter-subscription
function
From the /src/functions/newsletter-subscription
folder, run the following command:
fn deploy --app mushop-app
Run the following command (replace the placeholders with actual values you stored from previous steps):
fn config function mushop-app newsletter-subscription SMTP_USER [smtp_username]
fn config function mushop-app newsletter-subscription SMTP_PASSWORD [smtp_password]
fn config function mushop-app newsletter-subscription SMTP_HOST [smtp_host]
fn config function mushop-app newsletter-subscription SMTP_PORT [smtp_port]
fn config function mushop-app newsletter-subscription APPROVED_SENDER_EMAIL [approved_sender_email>
https://aaa.apigateway.us-ashburn-1.coi.customer-oci.com/newsletter
)
To invoke the function through the gateway, you can use the command below (replace the email with your actual email address and the API gateway URL with the real value):
curl -X POST -d '{"email": "youremail@example.com"}' https://aaa.apigateway.us-ashburn-1.oci.customer-oci.com/newsletter/subscribe
If everything succeeded, the function response will look similar to this one:
{"messageId":"<0cc76573-2b9b-5a22-6032-8b7e7fec8378@example.com>"}
You should also receive an email message to the address you provided above.