Skip to content

Commit 5d3b941

Browse files
committed
Fix: Allows usage of fully qualified ssm parameter names for ami-id
* Add expectation for IAM::Role policy to tests * Meet expectations added to tests fixes \#148
1 parent d696591 commit 5d3b941

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,11 @@ export class ImagePipeline extends Construct {
291291
* (only if a Parameter Store path is provided)
292292
*/
293293
if (props.amiIdSsmPath) {
294+
const amiIdSsmPath = props.amiIdSsmPath.replace(/^\/+/, '/');
294295
const amiSsmUpdateLambdaPolicy = new iam.PolicyDocument({
295296
statements: [
296297
new iam.PolicyStatement({
297-
resources: [`arn:aws:ssm:${props.amiIdSsmRegion}:${props.amiIdSsmAccountId}:parameter/${props.amiIdSsmPath}`],
298+
resources: [`arn:aws:ssm:${props.amiIdSsmRegion}:${props.amiIdSsmAccountId}:parameter${amiIdSsmPath}`],
298299
actions: [
299300
'ssm:PutParameter',
300301
'ssm:GetParameterHistory',
@@ -320,7 +321,7 @@ export class ImagePipeline extends Construct {
320321
handler: 'image-builder-lambda-update-ssm.lambda_handler',
321322
role: amiSsmUpdateLambdaRole,
322323
environment: {
323-
SSM_PATH: props.amiIdSsmPath,
324+
SSM_PATH: amiIdSsmPath,
324325
},
325326
memorySize: 256,
326327
});

test/imagepipeline.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,29 @@ test('Infrastructure Configuration IAM Role and Instance Profile are created', (
109109
});
110110

111111
test('IAM Role contains necessary permission set', () => {
112-
template.hasResourceProperties('AWS::IAM::Role',
113-
Match.anyValue());
112+
template.hasResourceProperties('AWS::IAM::Role', {
113+
Policies: [
114+
{
115+
PolicyName: 'AmiSsmUpdateLambdaPolicy',
116+
PolicyDocument: {
117+
Statement: [
118+
{
119+
Effect: 'Allow',
120+
Action: [
121+
'ssm:PutParameter',
122+
'ssm:GetParameterHistory',
123+
'ssm:GetParameter',
124+
'ssm:GetParameters',
125+
'ssm:AddTagsToResource',
126+
],
127+
Resource: 'arn:aws:ssm:us-east-1:11223344556:parameter/ec2-image-builder/al2-x86',
128+
},
129+
],
130+
},
131+
},
132+
],
133+
});
134+
114135
});
115136

116137
test('Infrastructure Configuration has the default instance types', () => {

0 commit comments

Comments
 (0)