Skip to content

Commit 559f3a9

Browse files
authored
feat(ingestor-api): expose ingestor handler role (#39)
* feat(ingestor-api) expose ingestor handler role * added a new public read only handler_role property to the StacIngestor construct * role name is automatically generated by AWS BREAKING CHANGE: the role name is automatically generated by AWS and thus users can not use the name that was specified before, but should directly interact with the new property we are adding. * change name of variable to comply with formatting rules, remove readonly statement
1 parent 5bcbe82 commit 559f3a9

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

lib/ingestor-api/index.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Construct } from "constructs";
1616

1717
export class StacIngestor extends Construct {
1818
table: dynamodb.Table;
19+
public handlerRole: iam.Role;
1920

2021
constructor(scope: Construct, id: string, props: StacIngestorProps) {
2122
super(scope, id);
@@ -31,6 +32,20 @@ export class StacIngestor extends Construct {
3132
...props.apiEnv,
3233
};
3334

35+
this.handlerRole = new iam.Role(this, "execution-role", {
36+
description:
37+
"Role used by STAC Ingestor. Manually defined so that we can choose a name that is supported by the data access roles trust policy",
38+
assumedBy: new iam.ServicePrincipal("lambda.amazonaws.com"),
39+
managedPolicies: [
40+
iam.ManagedPolicy.fromAwsManagedPolicyName(
41+
"service-role/AWSLambdaBasicExecutionRole",
42+
),
43+
iam.ManagedPolicy.fromAwsManagedPolicyName(
44+
"service-role/AWSLambdaVPCAccessExecutionRole",
45+
),
46+
],
47+
});
48+
3449
const handler = this.buildApiLambda({
3550
table: this.table,
3651
env,
@@ -91,23 +106,9 @@ export class StacIngestor extends Construct {
91106
dbSecret: secretsmanager.ISecret;
92107
dbVpc: ec2.IVpc;
93108
dbSecurityGroup: ec2.ISecurityGroup;
94-
subnetSelection: ec2.SubnetSelection;
109+
subnetSelection: ec2.SubnetSelection
95110
}): PythonFunction {
96-
const handler_role = new iam.Role(this, "execution-role", {
97-
description:
98-
"Role used by STAC Ingestor. Manually defined so that we can choose a name that is supported by the data access roles trust policy",
99-
roleName: `stac-ingestion-api-${props.stage}`,
100-
assumedBy: new iam.ServicePrincipal("lambda.amazonaws.com"),
101-
managedPolicies: [
102-
iam.ManagedPolicy.fromAwsManagedPolicyName(
103-
"service-role/AWSLambdaBasicExecutionRole",
104-
),
105-
iam.ManagedPolicy.fromAwsManagedPolicyName(
106-
"service-role/AWSLambdaVPCAccessExecutionRole",
107-
),
108-
],
109-
});
110-
111+
111112
const handler = new PythonFunction(this, "api-handler", {
112113
entry: `${__dirname}/runtime`,
113114
index: "src/handler.py",
@@ -117,7 +118,7 @@ export class StacIngestor extends Construct {
117118
vpc: props.dbVpc,
118119
vpcSubnets: props.subnetSelection,
119120
allowPublicSubnet: true,
120-
role: handler_role,
121+
role: this.handlerRole,
121122
memorySize: 2048,
122123
});
123124

@@ -132,7 +133,6 @@ export class StacIngestor extends Construct {
132133
);
133134

134135
props.table.grantReadWriteData(handler);
135-
props.dataAccessRole.grantAssumeRole(handler_role);
136136

137137
return handler;
138138
}

0 commit comments

Comments
 (0)