I am trying to create a lambda function through the AWS command.When I'm executing the below command Its gives me the Unknown option error.
AWS Command:
aws lambda create-function --function-name function_name ukmon-appd-disabled-
health-rules --runtime python3.7 --zip-file
fileb://bin/disabled_health_rules.zip --handler index.handler --timeout 10 -
-memory-size 1024 --role arn:aws:iam::99999999999:role/crossaccount
Error:
Unknown options: ukmon-appd-disabled-health-rules
I've tried with different names.I am not able to understand what does that error mean. Thanks in advance.
Remove the function_name. It is being recognized as the value to the parameter --function-name instead of the ukmon-appd-disabled-health-rules.
You have the argument function-name written twice. Just remove one like this
aws lambda create-function --function-name ukmon-appd-disabled-
health-rules --runtime python3.7 --zip-file
fileb://bin/disabled_health_rules.zip --handler index.handler --timeout 10 -
-memory-size 1024 --role arn:aws:iam::99999999999:role/crossaccount
Related
Hi I get this error when i try and create an Amplify Backend.
Seems to be realated to not being able to create lambda functions
aws lambda --profile haniq-main create-function --function-name my-function --zip-file fileb://function.zip --handler index.handler --runtime nodejs18.x --role arn:aws:iam::640766513655:role/lambda-ex
An error occurred (AccessDeniedException) when calling the CreateFunction operation: None
Well my account was blocked internally :)
I have an independent lambda layer, the arn is retrieved using the below CLI command.
aws lambda list-layer-versions --layer-name my-custom-lambda-layer --region us-east-1 --query 'LayerVersions[0].LayerVersionArn'
How can I refer this output to my cloud formation template, like below,
Resources:
Parameters:
MYLAYERARN: $(aws lambda list-layer-versions --layer-name my-custom-lambda-layer --region us-east-1 --query 'LayerVersions[0].LayerVersionArn')
Or use it directly in any of my lambda function as below,
Resources:
MyLambdaFuntion:
handler: Hello.lambda_handler
timeout: 60
memorySize: 256
layers:
- $(aws lambda list-layer-versions --layer-name my-custom-lambda-layer --region us-east-1 --query 'LayerVersions[0].LayerVersionArn')
Currenlty it is not executing the AWS CLI command, but taking the CLI command as the value
That is not possible, as you can't evaluate such expressions in a CloudFormation template.
The easiest solution would be to pass in the already-evaluated expression as a parameter.
Alternatively, if you must use a CloudFormation solution, then you could leverage a CloudFormation macro to invoke a lambda function which executes custom code (in this case, the code would have the SDK equivalent of the AWS CLI command).
More on CloudFormation macros:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-macros.html
Macro example: https://stackoverflow.com/a/70475459/3390419
When I try to trigger the update-function-code through the Command line, I'm getting an error "not reachable in this region".
I believe that my current config profile being in eu-west-2 region is conflicting with the function deployment to us-east-1. Without having to change my profile and/or region, what is the best way to allow my user to access/write to this regions lambda function
aws lambda update-function-code \
--function-name arn:aws:lambda:us-east-1:xxxxxxxx:function:xxxxxx \
--zip-file fileb://lambda_bundle.zip
ERROR:
An error occurred (ResourceNotFoundException) when calling the UpdateFunctionCode operation: Functions from 'us-east-1' are not reachable in this region ('eu-west-2')
Usually you would just add --region to your command:
aws lambda update-function-code \
--function-name arn:aws:lambda:us-east-1:xxxxxxxx:function:xxxxxx \
--zip-file fileb://lambda_bundle.zip \
--region us-east-1
I am trying to use environment variables for my lambda but when I run the following Lambda AWS CLI create-function command from a gradle task that runs a shell script,
aws $PROFILESTR lambda create-function \
--region us-east-1 \
--function-name MyLambda \
--zip-file fileb://$ZIP \
--role arn:aws:iam::$AWS_ACCT_ID:role/my_lambda \
--handler com.test.MyLambda::handleRequest \
--runtime java8 \
--description "Lambda description..." \
--memory-size 256 \
--timeout 45 \
--environment Variables={DEV_URL=dev,PROD_URL=prod}
it gives me this message and doesn't create the lambda function
:my-lambda:createLambda
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options: Variables=PROD_URL=prod
:my-lambda:createLambda FAILED
If I remove the second variable (declare only one env variable), it creates the function just fine.
From the lambda create-function cli documentation, the environment option accepts multiple variables:
--environment (structure)
The parent object that contains your environment's configuration
settings. Shorthand Syntax:
Variables={KeyName1=string,KeyName2=string}
I should be able to create the lambda through a script and not through AWS console (release should be automated).
What am I missing here or what am I doing wrong?
You should try with Variables="{KeyName1=string,KeyName2=string}"
The other option is to put the environment variables in a json file (ex: environment.json) and use that instead... and:
% aws lambda update-function-configuration --function-name MyLambda --environment file://environment.json
... or ... you could also use the file://environment.json command in your create-lambda statement
I am trying to create an AWS Lambda function using the command
aws lambda create-function \
--function-name foo\
--runtime nodejs\
--role lambda_basic_execution \
--handler asdf --zip-file "fileb:://boom.zip"
I have a file called boom.zip available in the directory. But I cannot deploy using the above command.
The failure message I get is
--zip-file must be a file with the fileb:// prefix.
Does anyone have a working example to create a lambda function using the AWS CLI?
You have an extra colon ':' in the file spec.
$ aws lambda create-function --function-name foo --runtime nodejs --role lambda_basic_execution --handler asdf --zip-file "fileb:://boom.zip"
--zip-file must be a file with the fileb:// prefix.
Example usage: --zip-file fileb://path/to/file.zip
$ aws lambda create-function --function-name foo --runtime nodejs --role lambda_basic_execution --handler asdf --zip-file "fileb://boom.zip"
Error parsing parameter '--zip-file': Unable to load paramfile fileb://boom.zip: [Errno 2] No such file or directory: 'boom.zip'
On mac I had to use absolute path, but added to the prefix there are actually 3 slashes.
Prefix:
fileb://
Path
/Users/myuser/Apps/folder/zips/file.zip
Complete
fileb:///Users/myuser/Apps/folder/zips/file.zip
I've had the same issue on Ubuntu 18.04 and what did the trick was enclosing both the name of the function and the fileb:/// with double " quotes.
aws lambda update-function-code --function-name "FUNCTION" --zip-file "fileb:///an/absolute/path/to/your/lambda/FUNCTION.zip"
For me, the issue occurred (in windows) because I didn't create the zip file correctly. I used the winrar tool to create the .rar file, changed the extension to .zip, and tried to upload the zip in the same way #helloV said (without double ::), but I got the same error message. If you are in windows make sure to follow this guide (for golang), or use any other suitable tool to create a correct zip file and try the command out again.