Fork me on GitHub
#aws-lambda
<
2017-10-26
>
gonewest81802:10:58

Having problems with lein-clj-lambda. I have a brand new AWS free tier account, and I just created a new IAM user. I installed the aws cli, and ran aws configure --profile adminuser, and for instance I can successfully run aws lambda list-functions --profile adminuser.

gonewest81802:10:44

But if I try running lein lambda -h from my clojure project I get a warning like this:

Oct 25, 2017 4:09:50 PM com.amazonaws.auth.profile.internal.BasicProfileConfigLoader loadProfiles
WARNING: The legacy profile format requires the 'profile ' prefix before the profile name. The latest code does not require such prefix, and will consider it as part of the profile name. Please remove the prefix if you are seeing this warning.

gonewest81802:10:41

So taking that warning at face value, I edited ~/.aws/config accordingly and discovered the lein plugin works but the AWS CLI no longer works. Making a mental note but moving on…

gonewest81802:10:18

Now lein lambda install test fails. What it does do is build the uberjar, creates an IAM role, creates the S3 bucket, uploads the jar to the bucket. But it fails to create the lambda function itself, throwing an exception instead

com.amazonaws.services.lambda.model.InvalidParameterValueException: The role defined for the function cannot be assumed by Lambda. (Service: AWSLambda; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

danielcompton03:10:23

Maybe check what version of the AWS CLI it expects to use?

danielcompton03:10:35

It may not be liking the newer versions

gonewest81803:10:26

The plugin doesn’t appear to be using the CLI itself, rather it’s using clj-lambda which in turn is a wrapper around the AWS java sdk. But point taken, I took the latest version of that java sdk so maybe I need to walk it back.

qqq04:10:39

@gonewest818: have you looked into #portkey ? I've been using it for the past few days, and 1. it's amazing, 2. the devs hangout in #portkey, and 3. they are very responsive to github issues

valtteri04:10:56

I always got confused with the aws configure and passing --profile switch around. It gets especially messy when working in multiple projects that involve several AWS accounts. Nowadays my workflow is that I have .env.sh script in each project directory which exports environment variables for aws-cli (and possibly other config as well). So when I switch to a project, I cd to project folder, run source .env and aws-cli is properly configured. Also aws-sdk will pick the configuration from environment variables when they’re set. http://docs.aws.amazon.com/cli/latest/userguide/cli-environment.html

gonewest81804:10:35

@qqq I will take a look. I did successfully revert the lein-clj-lambda dependency and got my ring-aws-lambda-adapter based lambda function uploaded and invokable. With this ring adapter I’m failing to understand (my fault, I’m skimming the docs as I go) what route gets called and how the parameters are presented in the request map, but at least I can see logs and know that the function is invokable. That’s a step ahead.

valtteri04:10:45

So @gonewest818 you could try just setting

export AWS_ACCESS_KEY_ID=xxxxx
export AWS_SECRET_ACCESS_KEY=yyyyy
export AWS_DEFAULT_REGION=us-east-1 # or whatever region you're targeting
Both aws-cli and aws-sdk are expected to pick config from env vars. EDIT: fixed wrong secret access key variable name

gonewest81805:10:13

I tried setting those but e.g. AWS_DEFAULT_REGION was ignored and the lein plugin would throw exceptions insisting I needed to specify a region anyway. Frustrating, to say the least. So I backed up to an older version of the plugin (one that predates a commit that claimed to change region setting). It was a lucky guess, but now at least I can deploy.

valtteri05:10:26

Ahhh yeah was it so that aws-cli expects AWS_DEFAULT_REGION and the sdk AWS_REGION.. so you probably need to set both.

export AWS_DEFAULT_REGION=us-east-1
export AWS_REGION=$AWS_DEFAULT_REGION
Yep, checked my own scripts and that’s how I usually have them set.

qqq05:10:08

@gonewest818: my minimal aws-lambda-portkey config is literally:

1. run 'aws configure'

2.
(ns server.snip.aws
  (:require [portkey.core :as pk]))

(defn h2 []
  (str "trying again this time with boot function"))

(pk/mount! h2 "/" :lambda-function-name "fn-live")

qqq05:10:39

the zip file generated is around 5.6 MB and takes about 2-3 seconds to upload