Skip to content

Instantly share code, notes, and snippets.

@alfonsodev
Created May 26, 2016 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfonsodev/73aec146b6ba838715dc40eae3fa4f8e to your computer and use it in GitHub Desktop.
Save alfonsodev/73aec146b6ba838715dc40eae3fa4f8e to your computer and use it in GitHub Desktop.
deploy lambda functions with aws-lambda-deploy

mkdir lambda-test && cd lambda-test git init echo 'node_modules' >> .gitignore npm init

maybe some of these are not need , need to clean up

npm install --save-dev babel-core babel-plugin-transform-object-rest-spread babel-plugin-transform-regenerator babel-polyfill babel-preset-es2015 babel-preset-react babel-preset-stage-0 dpl

babel-polyfill as prod package

npm install babel-polyfill

create babelrc with stage-0 enabled for async/await support

touch .babelrc

{
  "presets": ["es2015", "react", "stage-0"],
  "plugins": ["transform-regenerator"]

}

add deploy script to packages.json

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "deploy": "node ./node_modules/dpl/dpl.js"
},

add the repository information and files to deploy infor to your package.json

"repository": {
    "type": "git",
    "url": "git+https://github.com/youruser/lambda-test.git"
  },
  "files_to_deploy": [
     "package.json",
     "index.js"
   ],

remember to add babel-polyfill to the index.js

here the typical helloworld function , note the async keyword doesn't cause error :)

in index.js

require("babel-polyfill");

exports.handler = async function(event, context) {
    //console.log('Received event:', JSON.stringify(event, null, 2));
    console.log('value1 =', event.key1);
    console.log('value2 =', event.key2);
    console.log('value3 =', event.key3);
    context.succeed('{ ES7 in da house: ' + event.key1 + " } ");  // Echo back the first key value
    // context.fail('Something went wrong');
};

commit the changes, and get ready to deploy

git commit -am 'initial commit'

if your credentials are already in place under ~/.aws all you have to do is

export AWS_IAM_ROLE=arn:aws:iam::111111111111:role/lambda_deploy export AWS_REGION=eu-west-1 npm run deploy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment