Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (!this.options.region) {
throw new this.serverless.classes.Error('Please provide a region name.');
}
// validate stage/region
this.serverless.service.getStage(this.options.stage);
this.serverless.service.getRegionInStage(this.options.stage, this.options.region);
// TODO validate region is valid aws
const config = {
region: this.options.region,
};
this.CloudFormation = new AWS.CloudFormation(config);
BbPromise.promisifyAll(this.CloudFormation, { suffix: 'Promised' });
console.log('');
this.serverless.cli.log('Deploying Resources to AWS...');
// this.serverless.cli.spinner().start(); - weird bug!
return BbPromise.resolve();
}
return async (obj: ObserveResolverInfo, args: any, context: Observations, _info) => {
const params = obj[infoSym];
const queryId = computeQueryId(obj[infoSym], fieldName, args);
const client: any = new AWS.CloudFormation({
region: params.awsRegion,
accessKeyId: params.awsAccessKeyId,
secretAccessKey: params.awsSecretAccessKey,
});
// Make the query to AWS
const ret = await client[opName(fieldName)](args.body).promise();
context[queryId] = ret; //Overwrite in case data got updated on later query
return ret;
};
}
.then(() => {
console.info('Deletion of the AWS Cloud Formation stack is started...');
let cf = new AWS.CloudFormation({apiVersion: '2010-05-15', region: process.env['AWS_REGION']});
return cf.deleteStack({StackName: process.env['AWS_STACK_NAME']}).promise();
})
.then(() => {
const rp = require('minimal-request-promise'),
SEARCH_APPS_PATH = 'https://eqhtwlzt79.execute-api.us-east-1.amazonaws.com/Prod/search?query=',
AWS = require('aws-sdk'),
sar = new AWS.ServerlessApplicationRepository({ region: 'us-east-1' }),
cf = new AWS.CloudFormation({ region: 'us-east-1' });
module.exports = {
getAppById: function getApp(appId) {
return sar.getApplication({
ApplicationId: appId
}).promise()
.catch(error => {
console.log(error);
error.message = `Sorry, an error occurred when getting your application.`;
throw error;
});
},
searchApps: (searchTerm) => {
return rp.get(SEARCH_APPS_PATH+searchTerm)
.then(response => JSON.parse(response.body))
.then(body => body.Applications)
require('dotenv').config();
var fs = require("fs");
var AWS = require('aws-sdk');
var cloudformation = new AWS.CloudFormation({apiVersion: '2010-05-15'});
var FormConfig = require('./Config');
module.exports = function GetApiUrl(formName, stackId, callback) {
if(!stackId || typeof stackId !== "string"){
if(typeof stackId === "function"){
callback = stackId;
}
let rawdata = fs.readFileSync(`forms/${formName}/config.json`);
let obj = JSON.parse(rawdata);
var stackId = obj.stackId
}
var params = {
StackName: stackId,
LogicalResourceId: "RestApi",
};
cloudformation.describeStackResource(params, function(err, data) {
};
this.options.stage = this.options.stage
|| (this.serverless.service.defaults && this.serverless.service.defaults.stage)
|| 'dev';
this.options.region = this.options.region
|| (this.serverless.service.defaults && this.serverless.service.defaults.region)
|| 'us-east-1';
this.options.diffTool = this.options.diffTool;
this.options.localTemplate = this.options.localTemplate
|| '.serverless/cloudformation-template-update-stack.json';
this.options.orgTemplate = this.options.localTemplate.replace('.json', '.org.json');
AWS.config.update({ region: this.options.region });
this.cloudFormation = new AWS.CloudFormation();
}
return new BbPromise(function (resolve, reject) {
let cloudformation = new AWS.CloudFormation({ region: _this.evt.options.region })
let params = {
TemplateBody: JSON.stringify(resources)
}
cloudformation.validateTemplate(params, function (err, data) {
_this._spinner.stop(true)
if (err) {
throw new SError(err, SError.errorCodes.INVALID_PROJECT_SERVERLESS)
}
SCli.log('Resource Validator: Successful on "' + _this.evt.options.stage + '" in "' + _this.evt.options.region + '"')
return resolve()
})
})
})
return new Promise((resolve, reject) => {
let cloudformation = new AWS.CloudFormation({
region: paramsSSM.govRegion,
accessKeyId: paramsSSM.accessKey,
secretAccessKey: paramsSSM.secretKey
});
let params = {
StackName: 'gov-cloud-import'
};
let temp = {};
cloudformation.describeStacks(params, function(err, data) {
if (err){
if (err && err.statusCode == '400') {
temp.region = paramsSSM.govRegion;
temp.status = "Not Installed";
status.push(temp);
resolve("Not Installed");
} else {
const deployStack = (region, bucket) => {
const opts = { cwd: path.resolve(__dirname, '..' ) };
const cfn = new AWS.CloudFormation({ region });
const privateKey = fs.readFileSync(cli.flags.appKeyfile, 'utf8');
const preamble = [
exec('git rev-parse HEAD', opts),
cf.build(path.resolve(__dirname, '..', 'cloudformation', 'stork.template.js'))
];
if (cli.flags.kms) {
const kms = new AWS.KMS({ region });
preamble.push(encrypt(kms, cli.flags.npmToken));
preamble.push(encrypt(kms, privateKey));
preamble.push(encrypt(kms, cli.flags.githubToken));
}
return Promise.all(preamble).then((results) => {
const initAWSSDK = (context) => {
if (!cloudFormation) {
let awsConfig = { ...config.aws.CloudFormation }
if (context.awsRegion) {
awsConfig.region = context.awsRegion
}
cloudFormation = new CloudFormation(awsConfig);
}
return cloudFormation
}