Skip to content

edgarchinchilla/sls-basic-demo

Repository files navigation

EDGERCH: sls-basic-demo


A very basic demo project using serverless plugin to show a CloudFormation deploy

Clone the project:

mkdir ~/workspace
cd ~/workspace
git clone --progress https://github.com/edgarchinchilla/sls-basic-demo.git

Install dependencies:

npm install -g serverless
cd ~/workspace/sls-basic-demo && npm install

Create an AWS profile (optional):

aws configure --profile <name-of-your-project>-<stage>
AWS Access Key ID [None]: <access-key-id>
AWS Secret Access Key [None]: <secret-access-key>
Default region name [None]: <region>
Default output format [None]: json

NOTE: Even though you can skip this, we recommend the creation (on AWS IAM) and register (with the previous command) of new profile with the policy PowerUserAccess. You can create as many IAM Users/Profiles as you want, for example you can create one for your AWS DEV account and assign it to the serverless DEV stage and create one for your AWS PROD account and assign it to the serverless PROD stage.

Configure the project:

  • Initialize the project
cd ~/workspace/sls-basic-demo
serverless project init -n <name-of-your-project> -s <stage> -r <region> -c true
  • Update (by adding the provided keys) the serverless vars

    • _meta/variables/s-variables-<stage>-<region>.json

       {
           "message": "A message from Serverless ENV vars"
       }
  • Run the project locally (Emulate it)

cd ~/workspace/sls-basic-demo
serverless serve start -s <stage> -r <region>
  • Deploy project
cd ~/workspace/sls-basic-demo
serverless resources deploy -s <stage> -r <region>
serverless dash deploy -s <stage> -r <region>
    #Select all the resources -> Deploy
  • Getting relevant data

    After the execution of the previous commands, you can go to your _meta/variables/s-variables-<stage>-<region>.json and copy the new generated keys:

    • iamUserAccessKeyId

    • iamUserSecretAccessKey

    With this key pair you are ready to generate AWSv4 Signed requests to the generated APIG endpoint

    NOTE: You can get the APIG endpoint from the console after the serverless dash... command execution or you can go to the AWS console and search for a new APIG with the same name choosen for this project.

Use the generated APIG

The next example shows how to generate a very basic request (using Node.js) to the APIG generated by this project, in the example the request invokes the lambda for create a backup of the Auth0 Users Database:

    var https = require('https');
    var aws4  = require('aws4');
    
    var signer = new aws4.sign({
        service: 'execute-api',
        region: '<region>',
        path: '/<stage>/hello',
        host: '5aexamplebf.execute-api.us-east-1.amazonaws.com'
    }, {
        accessKeyId: '<your-generated-iamUserAccessKeyId>',
        secretAccessKey: '<your-generated-iamUserSecretAccessKey>'
    });
    
    https.request(signer, function(res) { res.pipe(process.stdout) }).end();

About

Very basic serverless plugin plugin project demo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published