Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(parent: Construct, name: string, props: BucketProps = {}) {
super(parent, name);
validateBucketName(props && props.bucketName);
const { bucketEncryption, encryptionKey } = this.parseEncryption(props);
const resource = new cloudformation.BucketResource(this, 'Resource', {
bucketName: props && props.bucketName,
bucketEncryption,
versioningConfiguration: props.versioned ? { status: 'Enabled' } : undefined,
lifecycleConfiguration: new Token(() => this.parseLifecycleConfiguration()),
});
applyRemovalPolicy(resource, props.removalPolicy);
this.versioned = props.versioned;
this.policy = props.policy;
this.encryptionKey = encryptionKey;
this.bucketArn = resource.bucketArn;
this.bucketName = resource.ref;
this.domainName = resource.bucketDomainName;
this.dualstackDomainName = resource.bucketDualStackDomainName;
// Add all lifecycle rules
(props.lifecycleRules || []).forEach(this.addLifecycleRule.bind(this));
}
if (props.allowAllOutbound !== false) {
this.connections.allowTo(new AnyIPv4(), new AllConnections(), 'Outbound traffic allowed by default');
}
this.role = new iam.Role(this, 'InstanceRole', {
assumedBy: new ServicePrincipal('ec2.amazonaws.com')
});
const iamProfile = new iam.cloudformation.InstanceProfileResource(this, 'InstanceProfile', {
roles: [ this.role.roleName ]
});
// use delayed evaluation
const machineImage = props.machineImage.getImage(this);
const userDataToken = new Token(() => new FnBase64((machineImage.os.createUserData(this.userDataLines))));
const launchConfig = new autoscaling.cloudformation.LaunchConfigurationResource(this, 'LaunchConfig', {
imageId: machineImage.imageId,
keyName: props.keyName,
instanceType: props.instanceType.toString(),
securityGroups: [this.securityGroup.securityGroupId],
iamInstanceProfile: iamProfile.ref,
userData: userDataToken
});
launchConfig.addDependency(this.role);
const minSize = props.minSize || 1;
const maxSize = props.maxSize || 1;
const desiredCapacity = props.desiredCapacity || 1;
constructor(parent: Construct, name: string, props: PrivateHostedZoneProps) {
super(parent, name);
validateZoneName(props.zoneName);
const hostedZone = new cloudformation.HostedZoneResource(this, 'Resource', {
vpcs: new Token(() => this.vpcs ? this.vpcs : undefined),
...determineHostedZoneProps(props)
});
this.hostedZoneId = hostedZone.ref;
this.zoneName = props.zoneName;
this.addVpc(props.vpc);
}
})],
});
for (const statement of (props.initialPolicy || [])) {
this.role.addToPolicy(statement);
}
const resource = new cloudformation.FunctionResource(this, 'Resource', {
functionName: props.functionName,
description: props.description,
code: props.code.toJSON(props.runtime),
handler: props.handler,
timeout: props.timeout,
runtime: props.runtime.name,
role: this.role.roleArn,
environment: new Token(() => this.renderEnvironment()),
memorySize: props.memorySize,
});
resource.addDependency(this.role);
this.functionName = resource.ref;
this.functionArn = resource.functionArn;
}
constructor(parent: Construct, name: string, props: SecurityGroupProps) {
super(parent, name, { securityGroupId: new Token(() => this.securityGroup.securityGroupId) });
const groupDescription = props.description || this.path;
this.securityGroup = new cloudformation.SecurityGroupResource(this, 'Resource', {
groupName: props.groupName,
groupDescription,
securityGroupIngress: new Token(() => this.directIngressRules),
securityGroupEgress: new Token(() => this.directEgressRules),
vpcId: props.vpc.vpcId,
});
this.groupName = this.securityGroup.ref;
this.vpcId = this.securityGroup.securityGroupVpcId;
}
constructor(parent: Construct, name: string, props: EventRuleProps = { }) {
super(parent, name);
const resource = new cloudformation.RuleResource(this, 'Resource', {
description: props.description,
state: props.enabled == null ? 'ENABLED' : (props.enabled ? 'ENABLED' : 'DISABLED'),
scheduleExpression: new Token(() => this.scheduleExpression),
eventPattern: new Token(() => this.renderEventPattern()),
targets: new Token(() => this.renderTargets())
});
this.ruleArn = resource.ruleArn;
this.addEventPattern(props.eventPattern);
this.scheduleExpression = props.scheduleExpression;
for (const target of props.targets || []) {
this.addTarget(target);
}
}
iamInstanceProfile: iamProfile.ref,
userData: userDataToken
});
launchConfig.addDependency(this.role);
const minSize = props.minSize || 1;
const maxSize = props.maxSize || 1;
const desiredCapacity = props.desiredCapacity || 1;
const asgProps: autoscaling.cloudformation.AutoScalingGroupResourceProps = {
minSize: minSize.toString(),
maxSize: maxSize.toString(),
desiredCapacity: desiredCapacity.toString(),
launchConfigurationName: launchConfig.ref,
loadBalancerNames: new Token(() => this.loadBalancerNames),
};
if (props.notificationsTopic) {
asgProps.notificationConfigurations = [];
asgProps.notificationConfigurations.push({
topicArn: props.notificationsTopic.ref,
notificationTypes: [
"autoscaling:EC2_INSTANCE_LAUNCH",
"autoscaling:EC2_INSTANCE_LAUNCH_ERROR",
"autoscaling:EC2_INSTANCE_TERMINATE",
"autoscaling:EC2_INSTANCE_TERMINATE_ERROR"
],
});
}
const subnets = props.vpc.subnets(props.vpcPlacement);
constructor(parent: Construct, name: string, props: SecurityGroupProps) {
super(parent, name, { securityGroupId: new Token(() => this.securityGroup.securityGroupId) });
const groupDescription = props.description || this.path;
this.securityGroup = new cloudformation.SecurityGroupResource(this, 'Resource', {
groupName: props.groupName,
groupDescription,
securityGroupIngress: new Token(() => this.directIngressRules),
securityGroupEgress: new Token(() => this.directEgressRules),
vpcId: props.vpc.vpcId,
});
this.groupName = this.securityGroup.ref;
this.vpcId = this.securityGroup.securityGroupVpcId;
}
constructor(parent: Construct, name: string, props: EventRuleProps = { }) {
super(parent, name);
const resource = new cloudformation.RuleResource(this, 'Resource', {
description: props.description,
state: props.enabled == null ? 'ENABLED' : (props.enabled ? 'ENABLED' : 'DISABLED'),
scheduleExpression: new Token(() => this.scheduleExpression),
eventPattern: new Token(() => this.renderEventPattern()),
targets: new Token(() => this.renderTargets())
});
this.ruleArn = resource.ruleArn;
this.addEventPattern(props.eventPattern);
this.scheduleExpression = props.scheduleExpression;
for (const target of props.targets || []) {
this.addTarget(target);
}
}
export function undefinedIfEmpty(f: () => T[]): Token {
return new Token(() => {
const array = f();
return (array && array.length > 0) ? array : undefined;
});
}