Skip to content

Commit

Permalink
Add to unit tests to check IAM policies have permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
samson-keung committed Jan 13, 2025
1 parent b4d9e7a commit 356d9a0
Showing 1 changed file with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,58 @@ describe('role', () => {
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::Lambda::Function', {
Role: {
'Fn::GetAtt': [
'MyRoleF48FFE04',
'Arn',
],
},
});
template.hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Action: 'lambda:InvokeFunction',
Effect: 'Allow',
Resource: [
{
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
{
'Fn::Join': [
'',
[
{
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
':*',
],
],
},
],
},
{
Action: 'lambda:GetFunction',
Effect: 'Allow',
Resource: {
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
},
],
Version: '2012-10-17',
},
});
});

it('uses default role otherwise', () => {
Expand All @@ -502,14 +546,58 @@ describe('role', () => {
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::Lambda::Function', {
Role: {
'Fn::GetAtt': [
'MyProviderframeworkonEventServiceRole8761E48D',
'Arn',
],
},
});
template.hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Action: 'lambda:InvokeFunction',
Effect: 'Allow',
Resource: [
{
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
{
'Fn::Join': [
'',
[
{
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
':*',
],
],
},
],
},
{
Action: 'lambda:GetFunction',
Effect: 'Allow',
Resource: {
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
},
],
Version: '2012-10-17',
},
});
});
});

Expand Down

0 comments on commit 356d9a0

Please sign in to comment.