Skip to content

Commit 422a084

Browse files
committed
move lambda creation to external template
1 parent 78a6a6b commit 422a084

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

.ebextensions/lambda-function.config

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
Resources:
2-
RandomNameFunction:
3-
Type: "AWS::Lambda::Function"
4-
Properties:
5-
Code:
6-
ZipFile: "PLACEHOLDER"
7-
Description: "Generate random names"
8-
Environment:
9-
Variables:
10-
REGION_NAME: {"Ref" : "AWS::Region"}
11-
TOPIC_ARN: {"Ref" : "NotificationTopic"}
12-
FunctionName: random-name
13-
Handler: index.handler
14-
Role: { "Fn::Join": [ "", [ "arn:aws:iam::",{"Ref" : "AWS::AccountId"},":role/service-role/scorekeep-lambda" ] ] }
15-
Runtime: nodejs4.3
16-
171
commands:
182
install-npm:
193
command: sudo -u ec2-user /tmp/install-npm.sh
@@ -48,7 +32,9 @@ files:
4832
#!/bin/bash
4933
REGION=$(/opt/elasticbeanstalk/bin/get-config environment -k AWS_REGION)
5034
STAGINGDIR=$(/opt/elasticbeanstalk/bin/get-config container -k container_staging_dir)
35+
TOPIC=$(/opt/elasticbeanstalk/bin/get-config environment -k NOTIFICATION_TOPIC))
5136
cd _lambda/random-name
5237
/home/ec2-user/bin/npm install
5338
zip -r ../random-name.zip *
5439
aws lambda update-function-code --function-name random-name --zip-file fileb://../random-name.zip --region $REGION
40+
aws lambda update-function-configuration --function-name random-name --environment "{\"Variables\": {\"NOTIFICATION_TOPIC\": \"$TOPIC\"} }"

_lambda/lambda-role.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,18 @@ Resources:
2020
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
2121
Path: /service-role/
2222
RoleName: scorekeep-lambda
23+
24+
RandomNameFunction:
25+
Type: "AWS::Lambda::Function"
26+
Properties:
27+
Code:
28+
ZipFile: "PLACEHOLDER"
29+
Description: "Generate random names"
30+
Environment:
31+
Variables:
32+
REGION_NAME: {"Ref" : "AWS::Region"}
33+
TOPIC_ARN: "PLACEHOLDER"
34+
FunctionName: random-name
35+
Handler: index.handler
36+
Role: { "Fn::Join": [ "", [ "arn:aws:iam::",{"Ref" : "AWS::AccountId"},":role/service-role/scorekeep-lambda" ] ] }
37+
Runtime: nodejs4.3

_lambda/random-name/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var AWSXRay = require('aws-xray-sdk-core');
22
var AWS = AWSXRay.captureAWS(require('aws-sdk'));
33

4-
AWS.config.update({region: process.env.REGION});
4+
AWS.config.update({region: process.env.AWS_REGION});
55
var Chance = require('chance');
66

77
var myFunction = function(event, context, callback) {

0 commit comments

Comments
 (0)