How to upload aws lambda layer deployment package to s3 bucket using aws cli? - amazon-web-services

I am trying to upload AWS Lambda's layer deployment package to s3 bucket using aws cli(since it's more than 50 megs), here is my command:
aws lambda publish-layer-version --layer-name “layer name” --description "Layer description” --content S3Bucket=“s3-name/location”,S3Key=“package.zip”,S3ObjectVersion=“1” --license-info "MIT" --compatible-runtimes "nodejs8.10" --zip-file "fileb:////tmp/package.zip"
I am just not sure about the --content part where I am specifying (S3Bucket, S3Key and S3ObjectVersion). N.B it works perfectly without --content
aws lambda publish-layer-version --layer-name “layer name” --description "Layer description” --content S3Bucket=“s3-name/location”,S3Key=“package.zip”,S3ObjectVersion=“1” --license-info "MIT" --compatible-runtimes "nodejs8.10" --zip-file "fileb:////tmp/package.zip"
With the above code, I get the following error message:
An error occurred (InvalidParameterValueException) when calling the PublishLayerVersion operation: Please do not provide other FunctionCode parameters when providing a ZipFile.

You can try and create a json file, let's say "myJson.json"
and put inside:
{
"S3Bucket": "s3-name",
"S3Key": "location/package.zip",
"S3ObjectVersion": "1"
}
then call it like this:
aws lambda publish-layer-version --layer-name “layer name” --description "Layer description” --content file://myJson.json --license-info "MIT" --compatible-runtimes "nodejs8.10" --zip-file file://tmp/package.zip
Please be aware you should execute the command where you created "myJson.json" (so move over to its location with "cd" command
By the way this :
--zip-file "file:////tmp/package.zip"
can be replaced by
--zip-file file://tmp/package.zip
Hope this helps

Related

Amplify Backend gives error The user does not have permissions to create triggers

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 :)

AWS - LAMBDA - CLI - update-function-code - not reachable in this region

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

ssm-agent trying to write to wrong region

When I execute aws SSM-Agent send-command on an instance, the SSM-Agent tries to write the results to an S3 bucket in another region.
How do I specify what region the target S3 bucket is in?
Here's the command and error I'm currently getting.
Execute the following from server A:
aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":[""]}]' --parameters '{"workingDirectory":[""],"executionTimeout":["3600"],"commands":["ps ax"]}' --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --output-s3-bucket-name "" --region us-east-1
And the log on server B shows:
Failed uploading /var/lib/amazon/ssm/<my-instance>/document/orchestration/<command-id>/awsrunShellScript/0.awsrunShellScript/stdout to s3://<my-bucket>/<command-id>/<my-instance>/awsrunShellScript/0.awsrunShellScript/stdout err:BucketRegionError: incorrect region, the bucket is not in 'eu-west-1' region
I don't have any resources in eu-west-1
Use argument --output-s3-region
https://docs.aws.amazon.com/cli/latest/reference/ssm/send-command.html

Which policy to grant to IAM user to create lambda deployment package in Python?

I want to create a lamba deployment package in python (with dependencies) using the Amazon tutorial.
When I push the .zip package with
aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip
I get the following error
An error occurred (AccessDeniedException) when calling the UpdateFunctionCode operation:
User: arn:aws:iam::<ACCOUNT-ID>:user/jeanclaude is not authorized to perform: lambda:UpdateFunctionCode
on resource: arn:aws:lambda:eu-west-3:<ACCOUNT-ID>:function:my-function
Which policy should I grant to jeanclaude to give him the correct access?
The User created in AWS IAM which is configured with your AWS CLI using access_key and secret_key should have enough privileges to interact with AWS Lambda.
I would prefer AWSLambdaFullAccess policy attached to your User/Role. This is just for testing purpose and later you can reduce the privileges if you want.
Once you have done the above then if you run the command
aws lambda update-function-code --function-name "helloworld" --zip-file "fileb://./helloworld.zip" --region "eu-west-2"
it should work, note that for update-function-code mandatory field is just the --function-name other fields are optional.aws cli update-fuction-code
Also please take a note of the create-function command it has just the following fields as mandatory and all other are optional aws cli docs
create-function
--function-name <value>
--runtime <value>
--role <value>
--handler <value>
and the --role here is the role required by the lambda while executing to interact with other services (not to be confused by the user above)
The user needs permission to UpdateFunctionCode for that ARN. More specific information is here.

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