How to get AWS lambda $LATEST evaluated? - amazon-web-services

I only keep the latest two versions of a lambda.
If I do:
$ aws lambda publish-version --function-name private-eye-converter-dev-pe-convert
I can see that the latest version is "Version": "27",.
But when I do:
$ aws lambda invoke --function-name my_lambda --cli-binary-format raw-in-base64-out \
--payload '{"key": "value"}' out --log-type Tail --query 'LogResult' \
--output text | base64 -d
START RequestId: f2bbdba7-c25b-460c-b72c-6c9afbf8afe0 Version: $LATEST
...
I got Version: $LATEST, which is helpless for me.
Is there a way of this $LATEST to show 27?
Sure
$ aws lambda invoke --function-name my_lambda:27
does, but I don't know which version is the latest a priori.

$LATEST is always the current, muttable version of the Lambda function. Sort of like a development version.
When you do Publish, you save all the current code and Lambda configuration to the function version, which you see as a version number.
The easiest way for you to always invoke the latest published version is to create an ALIAS for the Lambda function
When you do aws lambda publish in the response, you will receive the version number. You can use that to pass it in the second command
aws lambda update-alias (AWS CLI reference)and that way you automatically update the alias to the latest version. Then, when you invoke the lambda function with mylambda:myalias it will show the latest version number in logs.

Related

AWS - How can I create event source mapping for fifo lambda?

I'm trying to create an event source mapping with the AWS cli, but I keep getting a combination of errors that don't add up. Here's what I've tried:
aws lambda create-event-source-mapping --function-name someFunctionName --batch-size 100 --starting-position LATEST --event-source arn:aws:sqs:eu-central-1:someARN:SomeQueue.fifo
This results in: An error occurred (InvalidParameterValueException) when calling the CreateEventSourceMapping operation: StartingPosition
is not valid for SQS event sources.
Then I try without the starting position: aws lambda create-event-source-mapping --function-name someFunctionName --batch-size 100 --event-source arn:aws:sqs:eu-central-1:someARN:SomeQueue.fifo which results in: error: argument --starting-position is required
Am I missing something? How am I supposed to call this command?
aws -version tells me I'm running aws-cli/1.15.10 Python/2.7.9 Windows/2012Server botocore/1.10.10. Is this just an out of date version?
So, as I'm writing this question I upgrade the cli to 2.0.9 and option 2 works!!!
Upgraded the cli to 2.0.9 and option 2 works!!!

Is there a way to set the Amazon S3 link URL in Lambda all from the AWS-CLI?

Basically, I want to know if I can configure everything you see in this image from the AWS CLI. It seems like I can't.
Can I modify this Lambda config to provide an S3 link and function handler all from the CLI?
Yes, using the create-function call.
aws lambda create-function \
--runtime python3.6 \
--handler file_name.lambda_handler \
--code S3Bucket=mybucket,S3Key=path/to/object.zip

Run lambda function with localstack

I try to run my lambda function with localstack. I installed awscli-local and localstack
pip3 install awscli-local
pip3 install --user localstack --ignore-installed six
And then I started localstack
LAMDBA_EXECUTOR=docker localstack start --docker
When I now want to create my lambda function
aws lambda create-function --function-name Test --zip-file
fileb://myLambda.zip --handler index.handler --runtime
'nodejs6.10' --endpoint http://localhost:4574 --role admin
I get this error
An error occurred (ResourceConflictException) when calling the
CreateFunction operation: Function already exist: Test
Listing the functions returns nothing
aws lambda list-functions --endpoint http://localhost:4574
Does someone know why localstack thinks that the function is already there?
You can invoke lambdas directly in localstack from the Commandeer App. It installs localstack under the hood with docker.
There is a button on the lambda detail that allows you to specify the payload and then view the cloudwatch logs.
I'm also seeing this issue. Though it does not happen each time I try to create a lambda in localstack. What I have noticed is that lambda create seems to take a rather long time and cause a lot of CPU consumption on my mac while it is creating the lambda. My initial guess is that because of the time being take to create the ambda, something is timing out during the lambda creation and it's as if the creation is retried internally and it finds the lambda exits. If I query for the lambda after receiving this error message with awslocal, I see it exists.
I am running this on a MBP with 32Gb of memory and upped the allocation of resources to the Docker engine to 16Gb and 8 processors in hopes of solving this with additional resources, but that has not seemed to help. Suggestions welcome.

AWS lambda update-function-code with jar package via AWS CLI

I'm trying to update my lambda function code with jar from my local machine via AWS CLI.
The aws lambda has commands to update function code for zip file but not for jar.
I can upload by using s3 bucket, but I need to update from local itself.
I know following are the way to update from S3 bucket and for zip:
aws lambda update-function-code --function-name
--s3-bucket --s3-key
aws lambda update-function-code --function-name
--zip-file "fileb://"
I want to ask is there similar command exist for uploading jar as well?
You're probably missing the "fileb://" part for the jar.
aws lambda update-function-code --function-name my-lambda-name --zip-file fileb://./target/my-lambda-jar.1.0-SNAPSHOT.jar
run this command:
aws lambda update-function-code --function-name my-lambda-name --zip-file fileb://./target/my-lambda-jar.1.0-SNAPSHOT.jar

AWS CodeDeploy Most Recent Revision

I am using AWS CLI for CodeDeploy.
CodeDeploy is not deploying the most recent revision, instead it is deploying the last revision I manually deployed.
I have left the version and etag out of my cli command. As per the documentation:
(Optional) The Amazon S3 version identifier for the revision. (If the
version identifier is not specified, AWS CodeDeploy will use the most
recent version.)
aws deploy create-deployment --application-name MyApp --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name MyAppGroup --description "My App" --s3-location bucket=MyAppBucket,bundleType=zip,key=MyApp.zip
But it is not working. Any ideas? Is there a way to specifically enforce CodeDeploy to use the latest revision?
There is the S3 lifecycle to make sure the older versions are removed, but that is a hack at best. There needs to be an overwrite, or simply a way to force this.
By default, if you don't specify the version identifier when creating a deployment, CodeDeploy will try to deploy the latest revision by default according to http://docs.aws.amazon.com/codedeploy/latest/userguide/deployments-create-cli.html. But do you know how long do you create a deployment after push the new revision to S3?
Thanks,
Binbin
Here's a one-liner for that:
aws deploy list-application-revisions \
--sort-by registerTime --sort-order descending \
--application-name $MY_APPLICATION_NAME \
--region eu-central-1 --s3-bucket $MY_BUCKET \
--query 'revisions[0].s3Location.key' \
--output text --no-paginate
Flags --sort-by registerTime --sort-order descending sort the result such that we can parse out the first one easily (see --query).
Flags --output text --no-paginate returns the result in plain text instead of json. The --no-paginate option is required here due to an oddity with the cli to avoid returning the word "None" along with the results.
The --query flag parses the result, getting the key property of the s3Location object which is the first element of the revisions array.