Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CDK code #20

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions infrastructure/lib/constructs/opensearchCognito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Effect, FederatedPrincipal, ManagedPolicy, PolicyStatement, Role, Servi
import * as cognito from "aws-cdk-lib/aws-cognito";

export interface OpenSearchMetricsCognitoProps {
readonly region: string;
readonly openSearchDomainArn: string;
}

export class OpenSearchMetricsCognito extends Construct {
Expand Down Expand Up @@ -99,16 +99,16 @@ export class OpenSearchMetricsCognito extends Construct {
this.identityPoolAuthRole.addToPolicy(
new PolicyStatement({
effect: Effect.ALLOW,
actions: ['mobileanalytics:PutEvents', 'cognito-sync:*', 'cognito-identity:*', 'es:ESHttp*'],
resources: ['*'],
actions: ["es:ESHttpGet", "es:ESHttpPost"],
resources: [`${props.openSearchDomainArn}`],
}),
);

this.identityPoolAdminRole.addToPolicy(
new PolicyStatement({
effect: Effect.ALLOW,
actions: ['mobileanalytics:PutEvents', 'cognito-sync:*', 'cognito-identity:*', 'es:ESHttp*'],
resources: ['*'],
actions: ["es:ESHttp*", ],
resources: [`${props.openSearchDomainArn}`],
}),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
SubnetType,
Vpc,
AmazonLinuxGeneration,
AmazonLinuxImage
AmazonLinuxImage, MachineImage
} from 'aws-cdk-lib/aws-ec2';
import { Effect, ManagedPolicy, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
import {Aspects, CfnOutput, Duration, Tag, Tags} from 'aws-cdk-lib';
Expand Down Expand Up @@ -62,9 +62,7 @@ export class OpenSearchMetricsNginxCognito extends Construct {
instanceType: InstanceType.of(InstanceClass.M5, InstanceSize.LARGE),
blockDevices: [{ deviceName: '/dev/xvda', volume: BlockDeviceVolume.ebs(10) }], // GB
healthCheck: HealthCheck.ec2({ grace: Duration.seconds(90) }),
machineImage: new AmazonLinuxImage({
generation: AmazonLinuxGeneration.AMAZON_LINUX_2,
}),
machineImage: MachineImage.latestAmazonLinux2(),
// Temp added public subnet and IP, until backed up by ALB
associatePublicIpAddress: true,
allowAllOutbound: true,
Expand Down
5 changes: 3 additions & 2 deletions infrastructure/lib/stacks/opensearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class OpenSearchDomainStack extends Stack {
new PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ["sts:AssumeRole"],
resources: ['*'],
resources: [`arn:aws:iam::${props.account}:role/OpenSearchFullAccessRole`],
conditions: {
StringEquals: { 'aws:PrincipalAccount': props.account, 'aws:RequestedRegion': props.region,},
}
Expand All @@ -80,6 +80,7 @@ export class OpenSearchDomainStack extends Stack {
this.fullAccessRole = new Role(this, 'OpenSearchFullAccessRole', {
assumedBy: new CompositePrincipal(...secureRolesList.map((role) => new iam.ArnPrincipal(role.roleArn))),
description: "Master role for OpenSearch full access",
// The Name used in openSearchLambdaRole
roleName: "OpenSearchFullAccessRole",
inlinePolicies: {
"opensearchFullAccess": new PolicyDocument({
Expand All @@ -95,7 +96,7 @@ export class OpenSearchDomainStack extends Stack {
});

const metricsCognito = new OpenSearchMetricsCognito(this, "OpenSearchHealthCognito", {
region: props.region,
openSearchDomainArn: domainArn
});


Expand Down
6 changes: 2 additions & 4 deletions infrastructure/lib/stacks/opensearchNginxProxyReadonly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SubnetType,
Vpc,
AmazonLinuxGeneration,
AmazonLinuxImage
AmazonLinuxImage, MachineImage
} from 'aws-cdk-lib/aws-ec2';
import * as iam from "aws-cdk-lib/aws-iam";
import {Aspects, Duration, Stack, Tag, Tags} from 'aws-cdk-lib';
Expand Down Expand Up @@ -60,9 +60,7 @@ export class OpenSearchMetricsNginxReadonly extends Stack {
instanceType: InstanceType.of(InstanceClass.M5, InstanceSize.LARGE),
blockDevices: [{ deviceName: '/dev/xvda', volume: BlockDeviceVolume.ebs(10) }], // GB
healthCheck: HealthCheck.ec2({ grace: Duration.seconds(90) }),
machineImage: new AmazonLinuxImage({
generation: AmazonLinuxGeneration.AMAZON_LINUX_2,
}),
machineImage: MachineImage.latestAmazonLinux2(),
associatePublicIpAddress: false,
allowAllOutbound: true,
desiredCapacity: 2,
Expand Down
Loading