Skip to content

Instantly share code, notes, and snippets.

@joshhunt
Last active September 6, 2016 15:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshhunt/1c52cbfe8d5f60578656 to your computer and use it in GitHub Desktop.
Save joshhunt/1c52cbfe8d5f60578656 to your computer and use it in GitHub Desktop.

Running CoffeeScript on AWS Lambda

AWS Lambda does not have native support for running CoffeeScript. However, because you have any node module available to you, you can just using the coffee-script/register function to connect a CoffeeScript module to your AWS Lambda handler.

AWS Lambda function is configured as:

  • File name: index.js
  • Handler: handler
AWS = require 'aws-sdk'
s3 = new AWS.S3()
bucketName = 'lambda-test'
region = 'us-east-1'
key = 'testData.json'
module.exports = (event, context) ->
console.log JSON.stringify(event, null, 2)
console.log 'From SNS:', event.Records[0].Sns.Message
payload = {
key: 'myTestData'
event: event
}
s3.putObject {
Bucket: bucketName
Key: key
ContentType: 'application/json'
Body: JSON.stringify payload, null, 2
}, (err) ->
if err
console.log 'Error uploading'
console.log err
context.fail err
return
console.log "Successfully uploaded to s3:#{region}:#{bucketName}/#{key}"
context.succeed()
require('coffee-script/register')
exports.handler = require('./downloadData.coffee')
{
"name": "lambdaTest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.1.29",
"coffee-script": "^1.9.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment