Skip to content

Commit

Permalink
Merge pull request #118 from awslabs/bug/bucket_name
Browse files Browse the repository at this point in the history
feat(bugfix): Bug/bucket name
  • Loading branch information
dineshSajwan authored Nov 27, 2023
2 parents 8534135 + 48590d4 commit d965136
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 28 deletions.
7 changes: 4 additions & 3 deletions src/common/helpers/redis-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function buildRedisCluster(scope: Construct, props: RedisProps): elastica
numCacheNodes: numCacheNodes,
cacheSubnetGroupName: getRedisSubnetGroup(scope, props).ref,
vpcSecurityGroupIds: [props.redisSecurityGroup!.securityGroupId],
port: 8787,
port: props.redisPort,
});
return redisCulster;
}
Expand Down Expand Up @@ -113,9 +113,10 @@ export function getRedisSecurityGroup(scope: Construct,
}

export function setInboundRules(redisSecurityGroup:ec2.SecurityGroup,
sourceSecuritygroup:ec2.ISecurityGroup ) {
sourceSecuritygroup:ec2.ISecurityGroup,
redisPort:number) {
redisSecurityGroup.connections.allowFrom(sourceSecuritygroup,
ec2.Port.tcp(6379));
ec2.Port.tcp(redisPort));
}


Expand Down
26 changes: 25 additions & 1 deletion src/patterns/gen-ai/aws-qa-appsync-opensearch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ export class QaAppsyncOpensearch extends Construct {
{
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
encryption: s3.BucketEncryption.S3_MANAGED,
bucketName: 'qa-server-access-logs',
enforceSSL: true,
versioned: true,
lifecycleRules: [{
Expand Down Expand Up @@ -375,6 +374,31 @@ export class QaAppsyncOpensearch extends Construct {
},
});

// Minimum permissions for a Lambda function to execute while accessing a resource within a VPC
question_answering_function_role.addToPolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
'ec2:CreateNetworkInterface',
'ec2:DeleteNetworkInterface',
'ec2:AssignPrivateIpAddresses',
'ec2:UnassignPrivateIpAddresses',
],
resources: [
'arn:aws:ec2:'+Aws.REGION+':'+Aws.ACCOUNT_ID+':*/*',
],
}));
// Decribe only works if it's allowed on all resources.
// Reference: https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html#vpc-permissions
question_answering_function_role.addToPolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
'ec2:DescribeNetworkInterfaces',
],
resources: [
'*',
],
}));

// The lambda will access the opensearch credentials
if (props.openSearchSecret) {props.openSearchSecret.grantRead(question_answering_function_role);}

Expand Down
50 changes: 49 additions & 1 deletion src/patterns/gen-ai/aws-rag-appsync-stepfn-opensearch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ export class RagAppsyncStepfnOpensearch extends Construct {
{
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
encryption: s3.BucketEncryption.S3_MANAGED,
bucketName: 'rag-server-access-logs',
versioned: true,
lifecycleRules: [{
expiration: Duration.days(90),
Expand Down Expand Up @@ -466,6 +465,30 @@ export class RagAppsyncStepfnOpensearch extends Construct {
},
});

// Minimum permissions for a Lambda function to execute while accessing a resource within a VPC
s3_transformer_job_function_role.addToPolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
'ec2:CreateNetworkInterface',
'ec2:DeleteNetworkInterface',
'ec2:AssignPrivateIpAddresses',
'ec2:UnassignPrivateIpAddresses',
],
resources: [
'arn:aws:ec2:'+Aws.REGION+':'+Aws.ACCOUNT_ID+':*/*',
],
}));
// Decribe only works if it's allowed on all resources.
// Reference: https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html#vpc-permissions
s3_transformer_job_function_role.addToPolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
'ec2:DescribeNetworkInterfaces',
],
resources: [
'*',
],
}));

s3_transformer_job_function_role.addToPolicy(
new iam.PolicyStatement({
Expand Down Expand Up @@ -569,6 +592,31 @@ export class RagAppsyncStepfnOpensearch extends Construct {
},
});

// Minimum permissions for a Lambda function to execute while accessing a resource within a VPC
embeddings_job_function_role.addToPolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
'ec2:CreateNetworkInterface',
'ec2:DeleteNetworkInterface',
'ec2:AssignPrivateIpAddresses',
'ec2:UnassignPrivateIpAddresses',
],
resources: [
'arn:aws:ec2:'+Aws.REGION+':'+Aws.ACCOUNT_ID+':*/*',
],
}));
// Decribe only works if it's allowed on all resources.
// Reference: https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html#vpc-permissions
embeddings_job_function_role.addToPolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
'ec2:DescribeNetworkInterfaces',
],
resources: [
'*',
],
}));

embeddings_job_function_role.addToPolicy(
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
Expand Down
Loading

0 comments on commit d965136

Please sign in to comment.