Ghost Headless CMS: Weekly Newsletter

Just thought I’d share this. My colleague made an awesome demo of a Ghost (as a headless CMS) site and created a weekly newsletter to keep readers up-to-date.

Just thought I’d share :)

2 Likes

It was really awesome… Thanks @NatePDThompson

Hey @NatePDThompson Thanks for this amazing tutorial. Got a few questions though, I think they’re easy questions, you’ ll realize i am a beginner. Hope you can answer them! Thanks in advanced!

  1. On your tutorial you limit the iteration to 2 stories. We can see it here:


    Does that means users are going to receive 2 emails, if two stories are published (within the week) or are they going to receive just 1 email with the two stories?

  2. On the same file, (nl-stories-email.hbs) since you are using “published_at desc” i guess that means users will get only the latest post with the tag: nl-story. Is that correct?

  3. When you mention you used Cerberus, to design the emails, does that means you used Cerberus for the code inside the email.hbs file? Or did you used it elsewhere? if so? where did you use Cerberus? No need for npm here, right?

4.On your tutorial you mention “hitting the create button” of the Lamda function on AWS, after a few instructions but you don’t mention to anything about selecting the Create New API and then selecting a security mechanism for the API endpoint, i assumed this is what you meant:

4.1 When you state: “We will not need the DynamoDB persmission that the default template requires.” Do you just mean us to ignore the default template AWS gives (a template on an index.js file) when creating the Lamda function?

4.2. When you briefly mention the “environment variables for some settings” are you talking about these three only?:

SENDGRID_API_KEY
GHOST_HOST
GHOST_CONTENT_KEY

4.3 Is the key for GHOST_HOST env variable the domain name? Or what is the key for that variable?

  1. When you call to set the environmental variables on our Lambda function you mean we have to fill these spaces, am i correct?:

Well those are my only questions!! Sorry for the trouble but i am kind of new at this and some times have a little trouble filling the gaps on web dev instructions. And THANK YOU again for your tutorial!

Hey Luis,

I’m really glad you are giving it a shot! :slight_smile:

Here are the answers to your questions

  1. That would be one email with 2 stories in it
  2. That is correct
  3. No need for npm or anything. I used Cerberus templates as a baseline to design the actual email’s markup
  4. I believe these steps changed a bit since I wrote the post. But yes, you should select “Create a new API”. As a security model, you can either go with the API key or not. Mine was just plain “Open”.
    4.1. The Lambda blueprint we use as a baseline reads and writes stuff to DynamoDB. Since we rewrite the whole script and do not rely on DynamoDB anymore, no need for this permission.
    4.2. Yes, those 3 only
    4.3. GHOST_HOST is the full URL of your running Ghost instance
  5. Yes, precisely

When running this code -which requires the Ghost admin-api- , on AWS Lambda:

I get this error:

{
    "errorMessage": "Cannot read property 'split' of undefined",
    "errorType": "TypeError",
    "stackTrace": [
        "token (/var/task/node_modules/@tryghost/admin-api/lib/token.js:4:30)",
        "makeApiRequest (/var/task/node_modules/@tryghost/admin-api/lib/index.js:285:37)",
        "makeResourceRequest (/var/task/node_modules/@tryghost/admin-api/lib/index.js:245:16)",
        "Object.browse (/var/task/node_modules/@tryghost/admin-api/lib/index.js:127:20)",
        "handler (/var/task/index.js:15:47)"
    ]
}

I shipped the code to AWS Lambda using Node.js 8.16 and the runtime over there (on Lambda) is Node.js 8.10

Does that matters?

Thanks in advanced.

I was reading the admin-api docs and it says that:

34%20PM

But on the Enviromental variables on my Lambda function i have:

GHOST_HOST pointing to > https://mydomain.com

I guess thats just wrong then right?

The GHOST_HOST variable on this scenario should point to:

https://mydomain.com/admin/ghost/api/2.25.9/admin

is that correct? …anyone?

Turns out i did not had any GHOST_ADMIN_KEY declared as env variable at all on the AWS Lambda panel. :grinning: