Skip to content

Commit

Permalink
Merge pull request #20 from prudhvigodithi/main
Browse files Browse the repository at this point in the history
Update CDK code
  • Loading branch information
prudhvigodithi authored Apr 5, 2024
2 parents a8081be + 72bd700 commit a45a679
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
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
6 changes: 2 additions & 4 deletions infrastructure/lib/constructs/opensearchNginxProxyCognito.ts
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

0 comments on commit a45a679

Please sign in to comment.