aws-lambda

gonewest818 2017-10-26T02:19:58.000212Z

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.

gonewest818 2017-10-26T02:21:44.000095Z

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.

gonewest818 2017-10-26T02:23:41.000014Z

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…

gonewest818 2017-10-26T02:28:18.000118Z

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)

gonewest818 2017-10-26T02:33:21.000064Z

Ideas?

danielcompton 2017-10-26T03:03:23.000073Z

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

danielcompton 2017-10-26T03:03:35.000123Z

It may not be liking the newer versions

gonewest818 2017-10-26T03:17:26.000041Z

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.

qqq 2017-10-26T04:00:39.000154Z

@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

valtteri 2017-10-26T04:27:56.000111Z

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

gonewest818 2017-10-26T04:31:35.000190Z

@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.

valtteri 2017-10-26T04:32:45.000081Z

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

gonewest818 2017-10-26T05:00:13.000055Z

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.

valtteri 2017-10-26T05:06:26.000114Z

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.

qqq 2017-10-26T05:23:08.000147Z

@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")

qqq 2017-10-26T05:23:39.000014Z

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

👍 1