import l   from 'apex.js';
import AWS from 'aws-sdk';

import 'babel-polyfill';

const ec2    = new AWS.EC2();
const lambda = new AWS.Lambda();

export default l(async (event, context) => {
  console.log(`${context.functionName} has been invoked.`);

  const regions = (await ec2.describeRegions().promise()).Regions;

  const results = await Promise.all(regions.map(region => lambda.invoke({
    FunctionName:   'putLatestAmazonLinuxAmiInfoToS3',
    InvocationType: 'Event',

    Payload: JSON.stringify({
      bucket: event.bucket,
      region: region.RegionName,
    }),
  }).promise()));

  return {results};
});
Beispiel #2
0
import λ from 'apex.js';
import 'babel-polyfill';

import { getIdeas, createIdea } from './dynamo';

export default λ(event => {
    if (event.operation === 'read') {
        return getIdeas();
    }

    if (event.operation === 'create') {
        return createIdea(event.data);
    }

    return [];
});
Beispiel #3
0
import λ from 'apex.js';
import {decodeToken} from '../../lib/authorizer';
import {countByPostId, addComment, getByPostId, deleteComment} from '../../lib/comment_model';

export default λ((e, ctx) => {
  let postId = e.params.querystring.postId;
  const commentId = e.params.path.id;
  const httpMethod = e.context['http-method'];

  if(commentId) {
    if (httpMethod === "DELETE"){
      postId = e['body-json'].postId;
      const createdAt = e['body-json'].createdAt;
      return deleteComment(commentId, postId, Number(createdAt));
    }
  }
  if (postId) {
    if (httpMethod === "GET"){
      return showComment(postId);
    }
  }
  const params = {
    token: e.params.header.Authorization,
    desc: e['body-json'].desc,
    postId: e['body-json'].postId
  };
  return addComment(params);
});

const showComment = async postId => {
  return {
    comments: await getByPostId(postId),
Beispiel #4
0
import axios from 'axios'
import λ from 'apex.js'
import 'babel-polyfill'

export default λ(e => {
  console.log('fetching %d urls', e.urls.length)
  return Promise.all(e.urls.map(async function(url){
    console.log('fetching %s', url)
    return {
      status: (await axios.get(url)).status,
      url
    }
  }))
})
Beispiel #5
0
import 'babel-polyfill';
import λ from 'apex.js';
import {login} from '../../lib/user_model';

export default λ((e, ctx) => {
  if(!e['body-json'].username || !e['body-json'].password) return {"errorMessage": "username and password cannot be empty..."}
  const params = {
    username: e['body-json'].username,
    password: e['body-json'].password
  };
  return login(params);
});
Beispiel #6
0
import 'babel-polyfill';
import λ from 'apex.js';
import {register} from '../../lib/user_model';

export default λ((e, ctx) => {
  return register(e);
});
Beispiel #7
0
/**
 * @api {get} /superfeed_version Version
 * @apiGroup Info
 * @apiDescription Returns the current API version
 *
 * @apiSuccess {String} version The current API version
 */

import λ from 'apex.js'
import r from 'rethinkdb'
import { DB } from '../../db'

export const method = 'GET'
export const path = '/superfeed_version'

export const handler = async function () {
  let conn = await r.connect(DB)
  let { number } = await r.table('meta').get('version').run(conn)

  return { version: number }
}

export default λ(handler)
Beispiel #8
0
import 'babel-polyfill';
import λ from 'apex.js'
import EstimatedCharge from './rules/estimated_charge';

export default λ(() => {
  const job = new EstimatedCharge(process.env.SLACK_WEBHOOK_URL);

  return job
    .run()
    .then(() => console.log('Successfully notified of estimated charges.'));
});
Beispiel #9
0
import 'babel-polyfill';
import λ from 'apex.js'
import TrustedAdvisor from './rules/trusted_advisor';

export default λ(() => {
  const job = new TrustedAdvisor(process.env.SLACK_WEBHOOK_URL);

  return job
    .run()
    .then(() => console.log('Successfully reviewed trusted advisor findings.'));
});
Beispiel #10
0
import 'babel-polyfill';
import λ from 'apex.js';
import {decodeToken} from '../../lib/authorizer';
import {getAll, getById, addPost} from '../../lib/post_model';

export default λ((e, ctx) => {
  const postId = e.params.path.id;
  const httpMethod = e.context['http-method'];
  if (!postId) {
    if (httpMethod === "GET"){
      return getAll();
    }
    if (httpMethod === "POST") {
      const params = {
        token: e.params.header.Authorization,
        imageURL: e['body-json'].imageURL,
        desc: e['body-json'].desc
      };
      return addPost(params);
    }

  }

  if (postId) {
      return getById(postId);
  }
});
Beispiel #11
0
import lamda from 'apex.js';
import runGraphQL from '../../src/index';

export default lamda(event => runGraphQL(event));
import λ from 'apex.js';
import 'babel-polyfill';

export default λ(event => event.value.toUpperCase());