Giter Club home page Giter Club logo

aiham / ses-terraform-typescript-boilerplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from goldstack/ses-terraform-typescript-boilerplate

0.0 0.0 0.0 158.34 MB

Boilerplate for sending emails using Amazon Simple Email Service (SES) with TypeScript ready for deployment to AWS using low-cost, highly scaleable serverless infrastructure defined using Terraform.

Home Page: https://goldstack.party/templates/ses

JavaScript 1.69% TypeScript 2.79% HTML 91.13% HCL 4.38%

ses-terraform-typescript-boilerplate's Introduction

Generated with Goldstack

SES, Terraform and TypeScript Boilerplate

Codacy Badge

Boilerplate for sending emails using Amazon Simple Email Service (SES) with TypeScript using Yarn ready for deployment to AWS using low-cost, highly scaleable serverless infrastructure defined using Terraform.

This boilerplate has been automatically generated using the template:

Email Send (SES)

Feel free to fork this repository and modify it for your needs, or use the Goldstack project builder to generate a boilerplate specifically generated for your project.

โš ๏ธ Note that it often makes sense to use the Email Send template with a backend server. Thus before forking this boilerplate, consider if you would want to start with a project that contains a server template, such as Serverless API or Serverless Express.js.

Getting Started

Thank you for using this boilerplate. For any questions or feedback, please be welcome to raise an issue on GitHub ๐Ÿค— .

1. Fork and clone the repository

Fork this repository and then clone the fork into your local machine.

For more information, see GitHub documentation - Fork a repo

2. Install required local dependencies

A few dependencies need to be available in your development system. Please verify they are present or install them.

  • Node v12+
  • Yarn v1.22.5+
  • Docker v19+

Open a terminal and run the following commands:

node -v
yarn -v
docker --version

This should produce the following output:

Confirming versions in the console

If you need to install or update any of the dependencies, please see the following guides:

3. Initialise project and install NPM Dependencies

Run yarn in your project directory to install and download all dependencies.

The installation process should take around 3-10 minutes depending on the dependencies that need to be downloaded.

Installing project dependencies

You can confirm everything was installed correctly by running yarn -v. This should show a yarn version of 3.0.0+.

Confirming Yarn Version after install

4. Build modules

Make sure that the project compiles correctly by running yarn build your project directory:

Building your project

Note that this command also ensures that all TypeScript project references are configured correctly.

5. Configure VSCode

In order to setup VSCode, open the project in VSCode.

VSCode may prompt you to ask if you trust the authors of the workspace. Respond with Yes.

VSCode Prompt trust authors

You may also be asked if you want to install recommended extensions for this workspace. We recommend to do so since the template will be optimised to work with the suggested extensions.

VSCode Prompt install extensions

If you want to install the necessary extensions manually, here are links to the extensions required:

6. Initialise TypeScript

Locate a .ts or .tsx file in the workspace and open it. When asked whether to use the workspace TypeScript version, click Allow.

VSCode Locate TypeScript

In the status bar on the bottom right-hand corner of the VSCode editor you should now see TypeScript.

TypeScript status icon in VSCode

7. AWS Infrastructure Configuration

If you want to setup your SES email send infrastructure on AWS, you will need to make some changes to the configuration files included in this project.

Specifically, the goldstack.json in the packages/email-send folder.

{
  "$schema": "./schemas/package.schema.json",
  "name": "email-send",
  "template": "email-send",
  "templateVersion": "0.1.0",
  "configuration": {},
  "deployments": [
    {
      "name": "prod",
      "awsRegion": "us-west-2",
      "awsUser": "goldstack-dev",
      "configuration": {
        "domain": "email-send.templates.dev.goldstack.party",
        "hostedZoneDomain": "dev.goldstack.party"
      },
      "tfStateKey": "app-nextjs-bootstrap-1-prod-cd7f1f0a63ccb93ef36d.tfstate"
    }
  ]
}

The key properties you will need to update are:

  • deployments[0].configuration.hostedZoneDomain
  • deployments[0].configuration.domain

Also you need to delete deployments[0].tfStateKey.

For more information on these configuration options, see Goldstack Documentation / Email Send / Configure.

You will also need to ensure that you have a valid AWS user configure to deploy to AWS. For this, create a file in /config/infra/config.json (relative to project root).

{
  "users": [
    {
      "name": "goldstack-dev",
      "type": "apiKey",
      "config": {
        "awsAccessKeyId": "...",
        "awsSecretAccessKey": "...",
        "awsDefaultRegion": "us-west-2"
      }
    },
    {
      "name": "goldstack-prod",
      "type": "apiKey",
      "config": {
        "awsAccessKeyId": "...",
        "awsSecretAccessKey": "",
        "awsDefaultRegion": "us-west-2"
      }
    }
  ]
}

For more information on configuring your local AWS users, please see Goldstack Documentation / AWS Configuration.

Once your AWS user is configured you can run yarn infra up dev in the /packages/email-send folder. For more information on the infrastructure commands for this project, see Goldstack Documentation / Email Send / Infrastructure.

8. Local Development

This boilerplate will come with a module that provides the functionalities for email sending. This module is defined in packages/email-send. Generally you won't have to make changes to this module during local development. Instead, create an additional npm module in the packages/ folder and then import the email-send module as one of the dependencies.

Then use the exported connect() and getFromDomain() in your code to send email from your code:

const ses = await connect();
const fromDomain = await getFromDomain();
await ses
  .sendEmail({
    Destination: { ToAddresses: ['[email protected]'] },
    Message: {
      Subject: { Charset: 'UTF-8', Data: 'My email' },
      Body: {
        Text: {
          Charset: 'UTF-8',
          Data: 'This is the message body in text format.',
        },
      },
    },
    Source: 'sender@' + fromDomain,
  })
  .promise();

During local development and testing, a mocked email server will be used by default. The emails sent through the mocked server can be accessed through the exported getMockedSES():

const mockedSES = getMockedSES();
const sentEmailRequests = mockedSES.getSentEmailRequests();

9. Contribute to Goldstack

Have questions or ideas or want to contribute to the project? Please head over to github.com/goldstack/goldstack.

ses-terraform-typescript-boilerplate's People

Contributors

goldstack 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.