In my previous articles, I have demonstrated how to build a “Hello World” Apollo GraphQL Server with some common toolsets that I found useful during the development phase. I hope you have followed along our GraphQL journey and now it comes to a point that your Apollo Server is ready to deploy!

Server or Serverless — What’s the Deal?

Why serverless? It might be a decision made by your company’s solution architects for your upcoming projects, or you heard good (or bad) things about the “modern serverless approach” and just want to give it a test drive…whatever your reason is, I’ve got you covered 😉

Step 1: Setup AWS Environment

Before start getting your hands dirty into coding, you will need to do some configurations on your computer. I have to say this step is not something that I find interesting. That being said, it is essential to have our deployment configurations set up correctly, and it shouldn’t take too long to complete the configurations if you follow the key steps below.

We are going to deploy our Apollo Server on to Amazon Web Services (AWS)Create an AWS account if you don’t already have one. While AWS is a platform that provides paid services, it also offers generous free usage under the AWS Free Tier, which should be sufficient to cover the usage in this article. That said, you still need to be aware of the pricing, and consider setting up plans to manage services and resources consumed to avoid unexpected charges.

Once you’ve got your AWS account setup, you need to install the latest version of AWS CLI on your computer. Once installed, you can verify the installation by running an aws command. For example, the following command returns the current AWS CLI version installed on your computer:

$ aws --version

aws-cli/2.0.23 Python/3.7.4 Darwin/18.7.0 botocore/2.0.0

Next, you will need to configure the AWS CLI with user credentials. Basically, all you need to do it’s to run the aws configure command, which prompts for four pieces of information:

  • Access key ID
  • Secret access key
  • AWS Region
  • Output format

Follow this quick start guide to obtain the values required by the AWS CLI. As a best practice, be sure you create an Administrator IAM user and group when creating the access keys.

$ aws configure

AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json

The AWS CLI stores this information in a profile (a collection of settings) named default in the credentials file. By default, the information in this profile is used when you run an aws CLI command that doesn’t explicitly specify a profile to use. You can check the current configuration data by running the aws configure list command:

$ aws configure list

Name                    Value             Type    Location
----                    -----             ----    --------
profile                <not set>             None    None
access_key     ****************ABCD      config_file    ~/.aws/config
secret_key     ****************ABCD      config_file    ~/.aws/config
region                us-west-2              env    AWS_DEFAULT_REGION

Phew~That’s it! Your computer is now set up to interact with AWS.

#graphql #nodejs #aws #web-development

How to Build a Serverless Apollo GraphQL Server with AWS Lambda, Webpack and TypeScript
9.25 GEEK