File tree Expand file tree Collapse file tree
packages/cli/src/commands/lambda Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,14 +55,10 @@ describe("policies — buildPolicyDocument", () => {
5555
5656describe ( "policies — buildRoleTrustPolicy" , ( ) => {
5757 it ( "returns a sts:AssumeRole statement scoped to the requested service" , ( ) => {
58- const trust = buildRoleTrustPolicy ( "cloudformation" ) as {
59- Statement : { Action : string ; Principal : { Service : string } } [ ] ;
60- } ;
58+ const trust = buildRoleTrustPolicy ( "cloudformation" ) ;
6159 expect ( trust . Statement [ 0 ] ! . Action ) . toBe ( "sts:AssumeRole" ) ;
6260 expect ( trust . Statement [ 0 ] ! . Principal . Service ) . toBe ( "cloudformation.amazonaws.com" ) ;
63- const lambdaTrust = buildRoleTrustPolicy ( "lambda" ) as {
64- Statement : { Principal : { Service : string } } [ ] ;
65- } ;
61+ const lambdaTrust = buildRoleTrustPolicy ( "lambda" ) ;
6662 expect ( lambdaTrust . Statement [ 0 ] ! . Principal . Service ) . toBe ( "lambda.amazonaws.com" ) ;
6763 } ) ;
6864} ) ;
Original file line number Diff line number Diff line change @@ -36,6 +36,22 @@ interface PolicyDocument {
3636 Statement : PolicyStatement [ ] ;
3737}
3838
39+ /**
40+ * Trust-policy shape consumed by `policies role`. Has a `Principal`
41+ * field (which generic `PolicyStatement` does not model) — keep it as
42+ * a separate type rather than polluting the action-policy shape.
43+ */
44+ interface TrustPolicyStatement {
45+ Effect : "Allow" ;
46+ Principal : { Service : string } ;
47+ Action : "sts:AssumeRole" ;
48+ }
49+
50+ interface TrustPolicyDocument {
51+ Version : "2012-10-17" ;
52+ Statement : TrustPolicyStatement [ ] ;
53+ }
54+
3955/**
4056 * Actions the CLI needs to deploy/invoke/destroy the stack. Keep this
4157 * sorted alphabetically inside each service so diffs stay readable.
@@ -166,13 +182,8 @@ export function buildPolicyDocument(): PolicyDocument {
166182 } ;
167183}
168184
169- /**
170- * Trust policy a service-linked IAM role consumes (used by `policies role`).
171- * Returned as a structurally-correct `Allow sts:AssumeRole` with the named
172- * service principal attached — the `Principal` field is an IAM-specific
173- * extension not modelled by our generic `PolicyStatement` type.
174- */
175- export function buildRoleTrustPolicy ( principal : "lambda" | "cloudformation" ) : unknown {
185+ /** Trust policy a service-linked IAM role consumes (used by `policies role`). */
186+ export function buildRoleTrustPolicy ( principal : "lambda" | "cloudformation" ) : TrustPolicyDocument {
176187 const Service = principal === "lambda" ? "lambda.amazonaws.com" : "cloudformation.amazonaws.com" ;
177188 return {
178189 Version : "2012-10-17" ,
You can’t perform that action at this time.
0 commit comments