Deploying with AWS SAM and AWS CloudFormation

In this section, we will create a simple serverless application, which consists of a single function. It will return Amazon S3 bucket name that is specified as an environment variable.

Create the index.js file with the following code:

var AWS = require('aws-sdk'); exports.handler = function(event, context, callback) {   var bucketName = process.env.S3_BUCKET;   callback(null, bucketName); }

Create the packt.yaml file with the following code:

AWSTemplateFormatVersion: '2010-09-09'Transform: AWS::Serverless-2016-10-31Resources:  PacktFunction:    Type: AWS::Serverless::Function    Properties:      Handler: index.handler      Runtime: nodejs6.10      Environment:        Variables:           S3_BUCKET: packtdemo

Create the packt_app folder ...

Get Expert AWS Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.