Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
count: 1,
anyProperty: {
this: 'property can be any type supported by the AWS.DynamoDB.DocumentClient',
}
},
if: item => DynamoDB.attribute_not_exists(item.id)
});
newCount = 1;
}
return newCount;
});
// call the incrementer function from another Lambda Function
Lambda.schedule(stack, 'Caller', {
depends: incrementer.invokeAccess(),
schedule: Schedule.rate(Duration.minutes(1)),
}, async (_, incrementer) => {
const newCount = await incrementer.invoke({
id: 'id'
});
console.log(`new count of 'id' is ${newCount}`);
});
private createKubernetesResourceHandler() {
if (!this.kubectlEnabled) {
return undefined;
}
return new lambda.Function(this, 'KubernetesResourceHandler', {
code: lambda.Code.fromAsset(path.join(__dirname, 'k8s-resource')),
runtime: lambda.Runtime.PYTHON_3_7,
handler: 'index.handler',
timeout: Duration.minutes(15),
layers: [ KubectlLayer.getOrCreate(this) ],
memorySize: 256,
environment: {
CLUSTER_NAME: this.clusterName,
},
// NOTE: we must use the default IAM role that's mapped to "system:masters"
// as the execution role of this custom resource handler. This is the only
// way to be able to interact with the cluster after it's been created.
role: this._defaultMastersRole,
});
}
function renderDnsRecords(dnsRecordType: DnsRecordType, dnsTtl: Duration = Duration.minutes(1)): CfnService.DnsRecordProperty[] {
const ttl = dnsTtl.toSeconds();
if (dnsRecordType === DnsRecordType.A_AAAA) {
return [{
type: DnsRecordType.A,
ttl
}, {
type: DnsRecordType.AAAA,
ttl,
}];
} else {
return [{ type: dnsRecordType, ttl }];
}
}
deployBucket,
outputBucket,
}: {
scope: cdk.Construct
stack: string
stage: string
deployBucket: s3.IBucket
outputBucket: s3.IBucket
},
environment?: { [key: string]: string },
overrides?: Partial,
) => {
return new lambda.Function(scope, `EditionsArchiver${toTitleCase(name)}`, {
functionName: `editions-archiver-stepmachine-${name}-${stage}`,
runtime: lambda.Runtime.NODEJS_10_X,
timeout: Duration.minutes(5),
memorySize: 1500,
code: Code.bucket(
deployBucket,
`${stack}/${stage}/archiver/archiver.zip`,
),
handler: `index.${name}`,
environment: {
...environment,
stage: stage,
bucket: outputBucket.bucketName,
},
initialPolicy: [
new iam.PolicyStatement({
actions: ['*'],
resources: [
outputBucket.arnForObjects('*'),
TABLE_NAME: props.table.tableName,
READ: props.read ? 'TRUE' : '',
WRITE: props.write ? 'TRUE': '',
}
});
if (props.write) {
props.table.grantWriteData(this.fn);
}
if (props.read) {
props.table.grantReadData(this.fn);
}
new events.Rule(this, 'Tick', {
schedule: events.Schedule.rate(Duration.minutes(1)),
targets: [ new events_targets.LambdaFunction(this.fn) ]
});
}
}
constructor(scope: Construct, id: string, props: WatchApiGatewayProps) {
super(scope, id);
this.api = props.restApi.node.findChild('Resource') as apigw.CfnRestApi;
this.stage = props.restApi.deploymentStage.stageName;
this.watchful = props.watchful;
const alarmThreshold = props.serverErrorThreshold == null ? 1 : props.serverErrorThreshold;
if (alarmThreshold) {
this.watchful.addAlarm(
this.createApiGatewayMetric(ApiGatewayMetric.FiveHundredError)
.createAlarm(this, '5XXErrorAlarm', {
alarmDescription: `at ${alarmThreshold}`,
threshold: alarmThreshold,
period: Duration.minutes(5),
comparisonOperator: ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
evaluationPeriods: 1,
statistic: 'sum',
})
);
}
this.watchful.addSection(props.title, {
links: [{ title: 'Amazon API Gateway Console', url: linkForApiGateway(props.restApi) }]
});
[undefined, ...props.watchedOperations || []].forEach(operation =>
this.watchful.addWidgets(
this.createCallGraphWidget(operation, alarmThreshold),
...props.cacheGraph ? [this.createCacheGraphWidget(operation)] : [],
this.createLatencyGraphWidget(ApiGatewayMetric.Latency, operation),
this.createLatencyGraphWidget(ApiGatewayMetric.IntegrationLatency, operation),
super(scope, id);
const onEvent = new lambda.Function(this, 'OnEventHandler', {
code: lambda.Code.fromAsset(HANDLER_DIR),
description: 'onEvent handler for EKS cluster resource provider',
runtime: HANDLER_RUNTIME,
handler: 'index.onEvent',
timeout: Duration.minutes(1)
});
const isComplete = new lambda.Function(this, 'IsCompleteHandler', {
code: lambda.Code.fromAsset(HANDLER_DIR),
description: 'isComplete handler for EKS cluster resource provider',
runtime: HANDLER_RUNTIME,
handler: 'index.isComplete',
timeout: Duration.minutes(1)
});
this.provider = new cr.Provider(this, 'Provider', {
onEventHandler: onEvent,
isCompleteHandler: isComplete,
totalTimeout: Duration.hours(1),
queryInterval: Duration.minutes(5)
});
this.roles = [
onEvent.role!,
isComplete.role!,
];
}
}
constructor(scope) {
super(scope, 'pipeline');
let project = new Project(this, 'deploy-site', {
description: 'Deploys website at scaleyourcloudformation.com',
timeout: Duration.minutes(30),
badge: true,
source: Source.gitHub({
cloneDepth: 1,
owner: 'jeshan',
repo: 'scale-your-cloudformation',
webhookFilters: [
FilterGroup.inEventOf([EventAction.PUSH]).andBranchIs(
'master',
),
],
}),
environment: { buildImage: LinuxBuildImage.STANDARD_2_0 },
buildSpec: BuildSpec.fromObject({
version: '0.2',
phases: {
install: {
private createDynamoCapacityAlarm(type: string, metric: cloudwatch.Metric, provisioned: number, percent: number = DEFAULT_PERCENT) {
const periodMinutes = 5;
const threshold = calculateUnits(provisioned, percent, Duration.minutes(periodMinutes));
const alarm = metric.createAlarm(this, `CapacityAlarm:${type}`, {
alarmDescription: `at ${threshold}% of ${type} capacity`,
threshold,
period: Duration.minutes(periodMinutes),
comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
evaluationPeriods: 1,
statistic: 'sum',
});
return alarm;
}
}