How to create Lambda with given name?

0

I create a Lambda NET 6 and use Github workflow to build and deploy the lambda to AWS. All works fine but my Lambda created with a long name pm2dictx-app-dev-pm2dicts but not with a short as in yml file pm2dicts. I.e. Here is step in the Workflow file

APPLICATION_PACKAGE: pm2dictxlambda APPLICATION_NAME: pm2dictx-app LAMBDA_BUCKET_NAME: pm2dictx-bucket LAMBDA_STACK_NAME: pm2dictx-stack
...

name: Deploy lambda run: | aws cloudformation deploy --template-file ./aws/cfn/pm2dicts-lambda.yml --stack-name ${{ env.LAMBDA_STACK_NAME}} --parameter-overrides
Application=${{ env.APPLICATION_NAME }}
Environment=dev
LambdaName=pm2dicts
LambdaHandler=pm2dicts
LambdaBucketName=${{ env.LAMBDA_BUCKET_NAME }}
LambdaZipFile=${{ env.APPLICATION_PACKAGE }}-${{ github.sha }}.zip
--capabilities CAPABILITY_IAM

How can I create a Lambda with a short name as I need?

Oleg
asked 8 months ago243 views
2 Answers
1

First, make sure your CloudFormation template pm2dicts-lambda.yml has the Parameters section includes LambdaName parameter, e.g.,

Parameters:
  LambdaName:
    Type: String
  # ... rest of parameters

Next, make sure your AWS::Lambda::Function resource (or AWS::Serverless::Function if you use SAM extension) has its FunctionName references the Parameter named LambdaName, e.g.,

Resources:
  MyLambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName:
        Ref: LambdaName
      # ... rest of settings
profile picture
HS
answered 8 months ago
  • When I change
    FunctionName: !Sub ${Application}-${Environment}-${LambdaName} to #FunctionName: !Sub ${LambdaName} the Workflow completed with error aws cloudformation deploy --template-file ./aws/cfn/pm2dicts-lambda.yml --stack-name pm2dictx-stack --parameter-overrides
    Application=pm2dictx-app
    Environment=dev
    LambdaName=pm2dicts
    FunctionName=pm2dicts
    LambdaHandler=pm2dicts
    LambdaBucketName=pm2dictx-bucket
    LambdaZipFile=pm2dictxlambda-8be6e4aa7303adc00a9ba99e8c521a31988fedc3.zip
    --capabilities CAPABILITY_IAM shell: /usr/bin/bash -e {0} env: APPLICATION_PACKAGE: pm2dictxlambda APPLICATION_NAME: pm2dictx-app LAMBDA_BUCKET_NAME: pm2dictx-bucket LAMBDA_STACK_NAME: pm2dictx-stack SLN_WORKING_DIR: . AWS_DEFAULT_REGION: eu-west-2 AWS_REGION: eu-west-2 AWS_ACCESS_KEY_ID: *** AWS_SECRET_ACCESS_KEY: ***

    Waiting for changeset to be created.. Waiting for stack create/update to complete

    Failed to create/update the stack. Run the following command to fetch the list of events leading up to the failure aws cloudformation describe-stack-events --stack-name pm2dictx-stack Error: Process completed with exit code 255.

    But when I change it back it competed successfully and I see the Lambda with long name

  • It is so difficult to troubleshoot your issue without a detailed deployment error or full CloudFormation template. One possibility is that some of the short named resources already exist and you are not allowed to deploy the resource with the same name. Moreover, seems that you have merely commented out the function name with this.

    `#FunctionName: !Sub ${LambdaName}`
  • @HS I understand, I can provide my yml files but I do not see how to attach them here

1

Does it work if you specify FunctionName instead of LambdaName? This page refers to FunctionName.

AWS
Vincent
answered 8 months ago
  • Instead does not work because of error. It requires LambdaName. Wen I have added FunctionName=pm2dicts and FunctionName=pm2dicts in the command line the result is the same: it is again pm2dictx-app-dev-pm2dicts instead of pm2dicts

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions