Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function route({api, env, name, region, account, RouteKey}, callback) {
let gateway = new aws.ApiGatewayV2({region})
let lambda = new aws.Lambda({region})
let arn = `arn:aws:lambda:${region}:${account}:function:${name}-${env}-ws-${RouteKey.replace('$', '')}`
// used later
let integrationId
waterfall([
/**
* setup the integration
*/
function createIntegration(callback) {
setTimeout(function throttle() {
let uri = `arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${arn}/invocations`
// console.log(api)
gateway.createIntegration({
ApiId: api.ApiId,
// const url = new URL(uri);
const url = URL.parse(uri);
const payload = this.transformEvent(uri, param);
//! prepare lambda payload.
const params: Lambda.Types.InvocationRequest = {
FunctionName: url.hostname,
Payload: payload ? $U.json(payload) : '',
ClientContext: null,
// InvocationType: 'Event',
};
// _log(NS, `> params =`, $U.json(params));
//! call lambda.
const region = 'ap-northeast-2';
const lambda = new AWS.Lambda({ region });
const response = await lambda
.invoke(params)
.promise()
.catch((e: Error) => {
_err(NS, `! execute[${param.service || ''}].err =`, typeof e, e);
return this.doReportError(e, param.context, null, { protocol: uri, param });
})
.then((data: Lambda.Types.InvocationResponse) => {
_log(NS, `! execute[${param.service || ''}].res =`, $U.json(data));
const payload = data.Payload ? JSON.parse(`${data.Payload}`) : {};
const statusCode = $U.N(payload.statusCode || data.StatusCode, 200);
_log(NS, `> Lambda[${params.FunctionName}].StatusCode :=`, statusCode);
//! safe parse payload.body.
const body = (() => {
try {
if (payload.text && typeof payload.text == 'string') return payload.text;
grunt.registerMultiTask('deployLambda', DESC, function () {
var DEFAULTS = {
endpoint: 'iam.amazonaws.com'
};
var credentials = new AWS.SharedIniFileCredentials({profile: 'default'});
AWS.config.credentials = credentials;
var done = this.async();
AWS.config.update({region: 'us-east-1'});
var lambda = new AWS.Lambda({
apiVersion: '2015-03-31'
});
var iam = new AWS.IAM({apiVersion: '2010-05-08'});
iam.config.endpoint = DEFAULTS.endpoint;
iam.endpoint = DEFAULTS.endpoint;
// main
var subtasks = [];
subtasks.push(listRoles);
subtasks.push(createFunction);
async.series(subtasks, done);
function listRoles(callback) {
paramsRole = {}
iam.listRoles(paramsRole, function(err, data) {
async function setFunctionInvocationAlarms() {
await awsConfigHelper.updateConfig(cliArgs.region);
const lambda = new AWS.Lambda();
const cloudwatch = new AWS.CloudWatch();
while (!isCompleted) {
try {
const response = await lambda.listFunctions({
Marker: nextToken
}).promise();
if (response.Functions) {
for (let i = 0; i < response.Functions.length; i++) {
const fn = response.Functions[i];
if (cliArgs.filterName && !fn.FunctionName.match(filterRegex)) {
console.log("Skipping function", fn.FunctionName);
continue;
}
console.log(`Creating Invocation count Alarm for function: ${fn.FunctionName}`);
await cloudwatch.putMetricAlarm({
AlarmName: `${fn.FunctionName}_InvocationCount`,
exports.handler = (argv) => {
console.log('args: %j', argv);
aws.config.logger = process.stdout;
aws.config.region = argv.region;
const s3 = new aws.S3();
const lambda = new aws.Lambda();
paginate(s3, argv)
.flatMap(obj => get(s3, argv, obj))
.flatMap(event => invoke(lambda, argv, event))
.collect()
.each(list => console.log('count:', list.length))
;
}
const initServices = function () {
lambda = new aws.Lambda({region: lambdaConfig.region});
events = new aws.CloudWatchEvents({region: lambdaConfig.region});
},
getLambda = () => lambda.getFunctionConfiguration({FunctionName: lambdaConfig.name, Qualifier: options.version}).promise(),
const AWS = require('aws-sdk')
const lambda = new AWS.Lambda()
const ddb = new AWS.DynamoDB.DocumentClient({ region: process.env.AWS_REGION })
const getRules = async (
rulesToQuery,
queryFunc,
service,
tableName,
rangeKey
) => {
let rules = []
for (ruleSchema of rulesToQuery) {
let partialList = await queryFunc(
service,
tableName,
rangeKey,
ruleSchema
getPaymentSources(email){
var lambda;
if(process.env.NODE_ENV === 'development'){
lambda = new AWS.Lambda(require('./db').lambda)
} else {
lambda = new AWS.Lambda({
region: "us-west-1",
credentials: {
accessKeyId: process.env.REACT_APP_DB_accessKeyId,
secretAccessKey: process.env.REACT_APP_DB_secretAccessKey},
});
}
var payLoad = {
"stripeEmail": email
};
var params = {
FunctionName: 'retrieveCustomerSources',
Payload: JSON.stringify(payLoad)
};
let self =this
module.exports = function _create({app, queue, name}, callback) {
let lambda = new aws.Lambda({region: process.env.AWS_REGION})
lambda.getFunction({
FunctionName: name
},
function _getFunction(err) {
if (err && err.name === 'ResourceNotFoundException') {
print.create('@queues', name)
let read = _read.bind({}, queue)
let upload = _upload.bind({}, {app, queue, name})
waterfall([
iam,
read,
upload,
map,
], callback)
exports.lambdaGetPolicy = function(awsProfile, awsRegion, functionName) {
this.configAWS(awsProfile, awsRegion);
let lambda = new AWS.Lambda();
let params = {
FunctionName: functionName.trim(),
};
return new BbPromise(function(resolve, reject) {
lambda.getPolicy(params, function(err, data) {
if (err) {
return reject(err);
}
return resolve(data);
});
});