Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async default(inputs = {}) {
// use the inputs param to get component configuration from users of your component
// Show status...
this.context.status('Showing you around')
await utils.sleep(2000)
// Show a nicely formatted log statement...
this.context.log('This is a log statement')
this.context.log('------------')
await utils.sleep(2000)
// Show a nicely formatted debug statement...
this.context.log('Printing a "debug" statement (use "--debug" to see it)...')
this.context.log('')
this.context.debug('This is a debug statement visible when someone uses the "serverless --debug" option')
this.context.log('------------')
await utils.sleep(4000)
this.context.log('You can specify credentials in a ".env" file')
restApiId: apiId,
type: isLambda ? "AWS_PROXY" : "HTTP_PROXY",
integrationHttpMethod: "POST",
uri: isLambda
? `arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${endpoint.function}/invocations`
: endpoint.proxyURI
};
try {
await apig.putIntegration(integrationParams).promise();
} catch (e) {
if (e.code === "ConflictException") {
// this usually happens when there are too many endpoints for
// the same function. Retrying after couple of seconds ensures
// any pending integration requests are resolved.
await utils.sleep(2000);
return createIntegration({ apig, lambda, apiId, endpoint });
}
throw Error(e);
}
// Create lambda trigger for AWS_PROXY endpoints
if (isLambda) {
const permissionsParams = {
Action: "lambda:InvokeFunction",
FunctionName: functionName,
Principal: "apigateway.amazonaws.com",
SourceArn: `arn:aws:execute-api:${region}:${accountId}:${apiId}/*/*`,
StatementId: `${functionName}-${apiId}`
};
try {
await utils.sleep(2000)
// Show a nicely formatted debug statement...
this.context.log('Printing a "debug" statement (use "--debug" to see it)...')
this.context.log('')
this.context.debug('This is a debug statement visible when someone uses the "serverless --debug" option')
this.context.log('------------')
await utils.sleep(4000)
this.context.log('You can specify credentials in a ".env" file')
this.context.log('Serverless Components recognizes various ENV keys from popular cloud vendors and will add them to the "this.context.credentials" object.')
this.context.log('------------')
await utils.sleep(6000)
this.context.log('The "this.context" object features some useful info and methods.')
this.context.log('Use "this.context.resourceId()" to generate a string to use for cloud resource names, to ensure no name collisions occur:')
this.context.log('Here is the result of running "this.context.resourceId()": "' + this.context.resourceId() + '"')
this.context.log('------------')
await utils.sleep(3000)
// Save state
// This component's state and any child component states are saved in the .serverless directory
this.state.name = 'myComponent'
await this.save()
// Common provider credentials are identified in the environment or .env file and added to this.context.credentials
// The following line assumes you have the aws-sdk package installed locally
// const dynamodb = new AWS.DynamoDB({ credentials: this.context.credentials.aws })
async anything(inputs = {}) {
this.context.status('Running Anything')
await utils.sleep(6000)
}
}
Policy: JSON.stringify(cosBucketPolicy),
Region: region
})
} catch (e) {
throw e
}
handler = util.promisify(cos.putBucketWebsite.bind(cos))
try {
await handler(staticHostParams)
} catch (e) {
throw e
}
} catch (e) {
if (e.code === 'NoSuchBucket') {
await utils.sleep(2000)
return configureBucketForHosting(cos, bucketName, appid, region)
}
throw e
}
}
})
.promise()
await s3
.putBucketCors({
Bucket: bucketName,
CORSConfiguration: {
CORSRules: [putPostDeleteHeadRule, getRule]
}
})
.promise()
await s3.putBucketWebsite(staticHostParams).promise()
} catch (e) {
if (e.code === 'NoSuchBucket') {
await utils.sleep(2000)
return configureBucketForHosting(s3, bucketName)
}
throw e
}
}