Skip to content

Instantly share code, notes, and snippets.

@anthonygrees
Created March 20, 2020 00:07
Show Gist options
  • Save anthonygrees/cd1c91c70ec83b29b1766a98bf04b8e7 to your computer and use it in GitHub Desktop.
Save anthonygrees/cd1c91c70ec83b29b1766a98bf04b8e7 to your computer and use it in GitHub Desktop.
InSpec on AWS Lambda

aws_lambda

Use the aws_lambda resource to test a specific lambda.

Syntax

    describe aws_lambda do
      it { should exist}    
      its ('handler') { should eq 'main.on_event'}
      its ('version') { should eq '$LATEST' }
      its ('runtime') { should eq 'python3.7' }
    end

Parameters

This resource expects the name of the function.

Examples

tests that all lambdas with a particular tag is correctly deployed
      
    describe aws_lambda('my_new_lambda') do
        it { should exist}    
        its ('handler') { should eq 'main.on_event'}
        its ('version') { should eq '$LATEST' }
        its ('runtime') { should eq 'python3.7' }
    end
  }

aws_lambdas

Use the aws_lambdas resource to test the collection of lambdas deployed into an account.

Syntax

    describe aws_lambdas do
      its('count') { should eq 20 }
    end

Parameters

This resource does not expect any parameters.

Properties

Property Description
names The names of the lambda deployed.
tags The tags of the lambda deployed.

Examples

tests that all lambdas with a particular tag is correctly deployed
  lambdas = aws_lambdas() 
  describe lambdas do
    its ('count') { should eq 33}    
  end
  lambdas.tags.each_with_index { | tag, i |    
    if tag!= {} and tag.include? 'Application' and tag['Application']=='test')
      lambda_name = lambdas.names[i]
      
      describe aws_lambda(lambda_name) do
          it { should exist}    
          its ('handler') { should eq 'main.on_event'}
          its ('version') { should eq '$LATEST' }
          its ('runtime') { should eq 'python3.7' }
      end
    end
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment