Skip to content

Commit

Permalink
Updates scripts and fixes bug in lambda invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilaravi committed May 7, 2016
1 parent 48e6dfe commit 68b0868
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/services/playlistService.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';
var lambdaInvoke = require('../utils/lambda-invoke-promise');
var lambdaInvoke = require('../utils/lambda-invoke');

exports.addTrack = function (track) {
var params = {
FunctionName: 's3-save',
FunctionName: 's3-save-v1',
Payload: {
data: track,
bucket: process.env.S3_BUCKET
Expand All @@ -21,7 +21,7 @@ exports.addTrack = function (track) {

exports.retrievePlaylist = function (param) {
var params = {
FunctionName: 's3-get',
FunctionName: 's3-get-v1',
Payload: {
bucket: process.env.S3_BUCKET
}
Expand Down
4 changes: 2 additions & 2 deletions lib/services/suggestionsService.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';
var lambdaInvoke = require('../utils/lambda-invoke-promise');
var lambdaInvoke = require('../utils/lambda-invoke');

exports.retrieveSongSuggestions = function (query, limit) {
var params = {
FunctionName: 'song-suggester',
FunctionName: 'song-suggester-v1',
Payload: {
query,
limit
Expand Down
10 changes: 5 additions & 5 deletions lib/utils/lambda-invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ var AWS = require('aws-sdk');
var Lambda = new AWS.Lambda();
AWS.config.region = 'eu-west-1';

exports.invoke = function (functionName, payload) {
var params = {
FunctionName: functionName,
exports.invoke = function (params) {
var p = {
FunctionName: params.FunctionName,
InvocationType: 'RequestResponse',
Payload: JSON.stringify(payload),
Payload: JSON.stringify(params.Payload),
LogType: 'None'
};
return new Promise(function (resolve, reject) {
Lambda.invoke(params, function (err, data) {
Lambda.invoke(p, function (err, data) {
if (err) return reject(err);
var payload = JSON.parse(data.Payload);
if (payload.errorMessage) return reject(payload);
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-api.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

api_name='serverless-graphql-demo-fac'
api_name='serverless-graphql-demo-saturday'
api_description="Graphql endpoint"
root_path=/
resource_path=graphql
Expand Down
11 changes: 10 additions & 1 deletion scripts/create-iam.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
role_name='lambda_execution_s3_fac_test'
role_name='lambda_execution_weekend_test_1'

# IAM trust policy

Expand Down Expand Up @@ -44,6 +44,15 @@ aws iam put-role-policy \
"Resource": [
"arn:aws:s3:::*"
]
},
{
"Effect": "Allow",
"Action": [
"lambda:*"
],
"Resource": [
"arn:aws:lambda:*:*:*"
]
}
]
}'
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-s3-bucket.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bucket="serverless-graphql-demo-fac"
bucket="gql-test-1"
region="eu-west-1"

aws s3api create-bucket \
Expand Down

0 comments on commit 68b0868

Please sign in to comment.