When I try deploy to an existing lambda function configured in serverless.yml as following, it says "An error occurred: ApiLambdaFunction - an-existing-function-name-created-by-my-devops already exists."
functions:
api:
name: an-existing-function-name-created-by-my-devops
So it is not allowed to deploy to an existing lambda not created by serverless?
As Serverless manages your resources via a CloudFormation Stack, you could probably be able to import the lambda function within the UI (Import Existing Resources into a CloudFormation Stack) and do the deploy afterwards again.
I did not try this and there's most probably a better solution though.
Edit: precondition is that you successfully created your stack before adding your desired function.
Related
As the title suggests I am looking for a way to deploy a terraform file via an AWS lambda function. I would like to deploy this file via a time-based event. This is my first time working with terraform and I cannot seem to find anything pertaining to this specific use case.
I am much more versed in CloudFormation so normally what I would do is use the boto3 library to set up a lambda function that would deploy a CloudFormation stack. Does anyone know how to do this with a terraform file?
I have a java lambda function that requires access to a special non-java executable.
I've seen from the AWS docs that I can use a custom image (based on the java11 image) for my lambda function. My plan is to build an image that includes the special executable. The AWS docs describe how to do this and upload the image to ECR. However, I'm unclear about how I actually deploy my lambda using this custom container. At present the lambda is deployed using a cloud formation template that looks something like:
MyLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Description: My lambda function
Handler: com.foo.MyLambdaFunction::handleRequest
Runtime: java11
etc...
Am I supposed to edit the Runtime property? If so, to what? Do I need to deploy my lambda in a completely different way?
Any suggestions are welcome.
You can use the custom runtime identifier, which is specified on the bottom of this page.
If you are willing to use SAM, take a look at this.
I'm deploying an AWS lambda using CloudFormation.
In the template I use the flag AutoPublishAlias: v1 which should create a version, add the necessary permissions, and update the alias "v1" to point to the latest version.
When I deploy this change, I get the following error:
A version for this Lambda function exists ( 8 ). Modify the function to create a new version.
I am using CICD. Sometimes I redeploy the same lambda having modified another part of the CloudFormation template (e.g adding the AutoPublishAlias flag).
I thought CloudFormation was supposed to be able to handle this correctly - only updating resources which have changed?
So why am I seeing this error, and is there a workaround other than introducing a dummy code change?
Please see https://seed.run/docs/serverless-errors/a-version-for-this-lambda-function-exists.html
The error is not Cloudformation, it's Serverless telling CF to deploy a new lambda version, which is in fact the same one.
I saw this issue after upgrading from sls 1 to 2. Had to do dummy changes for every function at once.
After that haven't seen the issue come up.
I am developing aws lambda function and I have an option of using one of these two function, but I don't find any good place where I can see the difference between these two. Which one should be used and in which case?
AWS serverless application model i.e. AWS SAM is used to define a serverless application. You need to deploy this application on AWS lambda via s3.
SAM comes in action while testing the AWS Lambda Function locally because it's not easy to deploy and test on AWS Lambda every time you make a code change.
You can configure SAM on your IDE like eclipse, test and finalise the code then deploy it on Lambda.
For more info about sam https://github.com/awslabs/serverless-application-model/blob/master/HOWTO.md
So I have an existing CloudFormation stack up and running. However, I haven't found a solution for my problem, which is that I want my resources, for example EC2 and Lambda, to have up to date code.
It seems that a CloudFormation stack doesn't update if the template doesn't have any changes. I'm holding my code inside a S3 bucket as a zip-file, but if this file gets changed, CloudFormation doesn't notice it.
Is my best bet creating a git hook script that uses AWS CLI and updates the EC2 and Lambda code or is there some 'elegant' way for CloudFormation to notice these changes?
Create a new lambda function to update your existing lambda and ec2 or call the cloud formation to update them. On your S3, create an object Put event and call that new lambda function. So whenever a new file(zip) is put in s3, your ec2 & lambda gets updated.