Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
autoScalingGroup.connections.allowToAnyIpv4(ec2.Port.allUdp());
autoScalingGroup.connections.allowToAnyIpv4(ec2.Port.allIcmp());
const bootstrapEnabled = options.bootstrapEnabled !== undefined ? options.bootstrapEnabled : true;
if (options.bootstrapOptions && !bootstrapEnabled) {
throw new Error(`Cannot specify "bootstrapOptions" if "bootstrapEnabled" is false`);
}
if (bootstrapEnabled) {
const userData = renderUserData(this.clusterName, autoScalingGroup, options.bootstrapOptions);
autoScalingGroup.addUserData(...userData);
}
autoScalingGroup.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKSWorkerNodePolicy'));
autoScalingGroup.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKS_CNI_Policy'));
autoScalingGroup.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEC2ContainerRegistryReadOnly'));
// EKS Required Tags
Tag.add(autoScalingGroup, `kubernetes.io/cluster/${this.clusterName}`, 'owned', {
applyToLaunchedInstances: true
});
if (options.mapRole === true && !this.kubectlEnabled) {
throw new Error(`Cannot map instance IAM role to RBAC if kubectl is disabled for the cluster`);
}
// do not attempt to map the role if `kubectl` is not enabled for this
// cluster or if `mapRole` is set to false. By default this should happen.
const mapRole = options.mapRole === undefined ? true : options.mapRole;
if (mapRole && this.kubectlEnabled) {
// see https://docs.aws.amazon.com/en_us/eks/latest/userguide/add-user-role.html
this.awsAuth.addRoleMapping(autoScalingGroup.role, {
autoScalingGroup.connections.allowToAnyIpv4(ec2.Port.allTcp());
autoScalingGroup.connections.allowToAnyIpv4(ec2.Port.allUdp());
autoScalingGroup.connections.allowToAnyIpv4(ec2.Port.allIcmp());
const bootstrapEnabled = options.bootstrapEnabled !== undefined ? options.bootstrapEnabled : true;
if (options.bootstrapOptions && !bootstrapEnabled) {
throw new Error(`Cannot specify "bootstrapOptions" if "bootstrapEnabled" is false`);
}
if (bootstrapEnabled) {
const userData = renderUserData(this.clusterName, autoScalingGroup, options.bootstrapOptions);
autoScalingGroup.addUserData(...userData);
}
autoScalingGroup.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKSWorkerNodePolicy'));
autoScalingGroup.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKS_CNI_Policy'));
autoScalingGroup.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEC2ContainerRegistryReadOnly'));
// EKS Required Tags
Tag.add(autoScalingGroup, `kubernetes.io/cluster/${this.clusterName}`, 'owned', {
applyToLaunchedInstances: true
});
if (options.mapRole === true && !this.kubectlEnabled) {
throw new Error(`Cannot map instance IAM role to RBAC if kubectl is disabled for the cluster`);
}
// do not attempt to map the role if `kubectl` is not enabled for this
// cluster or if `mapRole` is set to false. By default this should happen.
const mapRole = options.mapRole === undefined ? true : options.mapRole;
if (mapRole && this.kubectlEnabled) {
// see https://docs.aws.amazon.com/en_us/eks/latest/userguide/add-user-role.html
public bind(task: sfn.Task): sfn.StepFunctionsTaskConfig {
// create new role if doesn't exist
if (this._role === undefined) {
this._role = new iam.Role(task, 'SagemakerTransformRole', {
assumedBy: new iam.ServicePrincipal('sagemaker.amazonaws.com'),
managedPolicies: [
iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonSageMakerFullAccess')
]
});
}
return {
resourceArn: getResourceArn("sagemaker", "createTransformJob", this.integrationPattern),
parameters: this.renderParameters(),
policyStatements: this.makePolicyStatements(task),
};
}
// Create a VPC
const vpc = new ec2.Vpc(this, 'CoffeeShopVPC', {
cidr: '10.0.0.0/16',
natGateways: 1
});
this.ecrRepository = new ecr.Repository(this, 'Repository', {
repositoryName: DOCKER_IMAGE_PREFIX,
removalPolicy: cdk.RemovalPolicy.DESTROY
});
const buildRole = new iam.Role(this, 'CodeBuildIamRole', {
assumedBy: new iam.ServicePrincipal('codebuild.amazonaws.com')
});
buildRole.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName("AWSLambdaFullAccess"));
buildRole.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName("AmazonAPIGatewayAdministrator"));
buildRole.addToPolicy(new iam.PolicyStatement({
resources: ['*'],
actions: ['cloudformation:*']
}));
buildRole.addToPolicy(new iam.PolicyStatement({
resources: ['*'],
actions: ['iam:*']
}));
buildRole.addToPolicy(new iam.PolicyStatement({
resources: ['*'],
actions: ['ecr:GetAuthorizationToken']
}));
if (props.periodic) {
sourceDetails.push({
eventSource: 'aws.config',
maximumExecutionFrequency: props.maximumExecutionFrequency,
messageType: 'ScheduledNotification'
});
}
props.lambdaFunction.addPermission('Permission', {
principal: new iam.ServicePrincipal('config.amazonaws.com')
});
if (props.lambdaFunction.role) {
props.lambdaFunction.role.addManagedPolicy(
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSConfigRulesExecutionRole')
);
}
// The lambda permission must be created before the rule
this.node.addDependency(props.lambdaFunction);
const rule = new CfnConfigRule(this, 'Resource', {
configRuleName: this.physicalName,
description: props.description,
inputParameters: props.inputParameters,
maximumExecutionFrequency: props.maximumExecutionFrequency,
scope: Lazy.anyValue({ produce: () => this.scope }),
source: {
owner: 'CUSTOM_LAMBDA',
sourceDetails,
sourceIdentifier: props.lambdaFunction.functionArn
super(scope, id, props);
// Create a VPC
const vpc = new ec2.Vpc(this, 'CoffeeShopVPC', {
cidr: '10.0.0.0/16',
natGateways: 1
});
this.ecrRepository = new ecr.Repository(this, 'Repository', {
repositoryName: DOCKER_IMAGE_PREFIX,
removalPolicy: cdk.RemovalPolicy.DESTROY
});
const buildRole = new iam.Role(this, 'CodeBuildIamRole', {
assumedBy: new iam.ServicePrincipal('codebuild.amazonaws.com')
});
buildRole.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName("AWSLambdaFullAccess"));
buildRole.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName("AmazonAPIGatewayAdministrator"));
buildRole.addToPolicy(new iam.PolicyStatement({
resources: ['*'],
actions: ['cloudformation:*']
}));
buildRole.addToPolicy(new iam.PolicyStatement({
resources: ['*'],
actions: ['iam:*']
}));
buildRole.addToPolicy(new iam.PolicyStatement({
resources: ['*'],
actions: ['ecr:GetAuthorizationToken']
}));
constructor(scope: cdk.Construct, id: string, props: LambdaDeploymentGroupProps) {
super(scope, id, {
physicalName: props.deploymentGroupName,
});
this.application = props.application || new LambdaApplication(this, 'Application');
this.alarms = props.alarms || [];
this.role = props.role || new iam.Role(this, 'ServiceRole', {
assumedBy: new iam.ServicePrincipal('codedeploy.amazonaws.com')
});
this.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSCodeDeployRoleForLambda'));
this.deploymentConfig = props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES;
const resource = new CfnDeploymentGroup(this, 'Resource', {
applicationName: this.application.applicationName,
serviceRoleArn: this.role.roleArn,
deploymentGroupName: this.physicalName,
deploymentConfigName: this.deploymentConfig.deploymentConfigName,
deploymentStyle: {
deploymentType: 'BLUE_GREEN',
deploymentOption: 'WITH_TRAFFIC_CONTROL'
},
alarmConfiguration: cdk.Lazy.anyValue({ produce: () => renderAlarmConfiguration(this.alarms, props.ignorePollAlarmsFailure) }),
autoRollbackConfiguration: cdk.Lazy.anyValue({ produce: () => renderAutoRollbackConfiguration(this.alarms, props.autoRollback) }),
});
this.deploymentGroupName = this.getResourceNameAttribute(resource.ref);
constructor(scope: Construct, id: string, props: CloudFormationStackDriftDetectionCheckProps = {}) {
super(scope, id, {
...props,
identifier: 'CLOUDFORMATION_STACK_DRIFT_DETECTION_CHECK',
inputParameters: {
cloudformationRoleArn: Lazy.stringValue({ produce: () => this.role.roleArn })
}
});
this.scopeToResource('AWS::CloudFormation::Stack', props.ownStackOnly ? Stack.of(this).stackId : undefined);
this.role = props.role || new iam.Role(this, 'Role', {
assumedBy: new iam.ServicePrincipal('config.amazonaws.com'),
managedPolicies: [
iam.ManagedPolicy.fromAwsManagedPolicyName('ReadOnlyAccess')
]
});
}
}