A Grunt utlitiy for deploying an AWS Lambda function package stored in S3
npm install grunt-deploy-lambdaUse of this package requires that you have installed the Grunt CLI and package via npm install grunt, in addition to this package.
Use of this package also requires a valid grunt configuration (which can be done in code via grunt.initConfiguration()), where validity is described with each respective task.
You may access these tasks programmatically after loading package into your grunt via: ~~grunt.loadNpmTasks('@onaje/grunt-deploy-lambda');~~grunt.loadNpmTasks('grunt-deploy-lambda');
example CLI usage: grunt deploy_lambda_from_s3:default --aws-profile=default
NOTE: The "--aws-profile" option overries any options.awsProfile specified in your target configuration.
Similarly, setting the environment variable AWS_PROFILE will override any specified "--aws-profile" option as well as any target configuration.
default task configuration for the following configuration parameters:"myS3Packages/lambdaFunctionPackage.zip")~/.aws/credentialsdefault.lambdaConfigOptions you may have set. Your lambda's configuration will simply not be updated.Below shows an example grunt configuration for two target configs: default (required) and alternate:
deploy_lambda_from_s3: {
default: {
packagePath: 'cf-tutorial_0-0-1_2018-4-11-12-53-4.zip',
bucket: 'my-default-s3-bucket',
functionArn: 'arn:aws:lambda:us-east-1:5555555:function:myDefaultLambda',
lambdaConfigOptions: {
memory: 128, // MB
runtime: 'nodejs',
timeout: 3, // seconds
handler: 'index.handler',
role: 'myExecutionRole'
},
options: {
awsProfile: 'default'
}
},
alternate: {
packagePath: 'some/path/to/overriding_package.zip',
bucket: 'takes-presedence-over-default-bucket',
//functionArn: 'commented out--will fall back to default.functionArn',
lambdaConfigOptions: {
//memory: 256, commented out -- will NOT fall back to default.lambdaConfigOptions.memory
runtime: 'nodejs4.3',
timeout: 15,
},
options: {
awsProfile: 'sandbox'
}
}
}
__ (e.g. outerObj_innerObjEnvKey)__)example CLI usage: grunt update_lambda_environment:production --aws-profile=onaje
NOTE: The "--aws-profile" option overrides any options.awsProfile specified in your target configuration.
Similarly, setting the environment variable AWS_PROFILE will override any specified "--aws-profile" option as well as any target configuration.
As of v0.5.0, you also have the option of preceding all your environment variables with some prefix envVariablePrefix. If not set, this task will not fall back to some default.envVariablePrefix; you simply wont have prefixes on your env variables.
default task configuration for the following config parameters:default.envVariablePrefix~/.aws/credentialsBelow shows an example grunt configuration for two target configs: default (required) and alternate:
update_lambda_environment: {
default: {
functionArn: 'arn:aws:lambda:us-east-1:5555555:function:myDefaultLambda',
envFilePath: '~/grunt-deploy-lambda/test/defaultEnv.js',
envVariablePrefix: 'myApp_',
options: {
awsProfile: 'default'
}
},
alternate: {
functionArn: 'arn:aws:lambda:us-east-1:5555555:function:anotherLambda',
//envFilePath: '../test/alternateEnv.js', commented out--will fall back to default.envFilePath
envVariablePreifx: 'myOtherApp_',
options: {
awsProfile: 'sandbox'
}
}
}
Please feel free to take a look at the Gruntfile in my test directory for further explanation/commentary.
[1]:*awsProfile is an optional specificaiton per configuration; if not specified, it will default to whatever "default" profile credentials
contianed in your local ~/.aws/credentials file.