0
votes

The artefact that I create and deploy has a version number in it. It is of the form:

universe-0.0.1-SNAPSHOT.zip

where the 0.0.1-SNAPSHOT is the version.

Now the CloudFormation template has the Handler mapped through a Fn::Join function:

  UFunctionCelestial:
    Type: AWS::Lambda::Function
    Properties:
      Code:
        S3Bucket: !Ref ArtefactRepositoryBucket
        S3Key: !Join [ '', [!Sub '${AWS::StackName}-', !Ref CodeVersion, '.zip' ] ]
      Handler: !Join [ '', [!Sub '${AWS::StackName}-', !Ref CodeVersion, '/src/lambdas/celestial_persist_function.handler'] ]
      Role: !GetAtt [ UIAMRoleFunctionServiceRoleCelestial, Arn ]
      Runtime: python3.7
      Environment:
        Variables:
          CELESTIAL_TABLE_NAME: !Ref UTableCelestial
          PRIMARY_KEY: id
    DependsOn:
      - UIAMRoleFunctionServiceRolePolicyCelestial
      - UIAMRoleFunctionServiceRoleCelestial

...SNIP...

Parameters:
  ArtefactRepositoryBucket:
    Type: String
    Description: S3 bucket for asset "foundry-cdk/CelestialHandler/Code"
  CodeVersion:
    Type: String
    Description: S3 key for asset version "foundry-cdk/CelestialHandler/Code"

I guess most of this is irrelevant, except the Handler property

Now the !Ref CodeVersion code version for that line seems to evaluate as 0/0/1-SNAPSHOT for some reason, even though I call this template with the command:

aws2 cloudformation deploy \
    --template-file ${CF_TEMPLATE_FILE} \
    --region ${ACCOUNT_REGION} \
    --stack-name ${PROJECT_NAME} \
    --force-upload \
    --capabilities CAPABILITY_IAM \
    --parameter-overrides \
        ArtefactRepositoryBucket=${S3_AWS_RELEASES_BUCKET} \
        CodeVersion=${APPLICATION_VERSION}

I echoed out the ${APPLICATION_VERSION} and, yep, it evaluates to 0.0.1-SNAPSHOT

and yet when I go to the console and look at my Lambda I get the message:

Lambda can't find the file universe-0/0/1-SNAPSHOT/src/lambdas/celestial_persist_function.py. Make sure that your handler upholds the format: file-name.method.

So my question is, why is CloudFormation turning my dots into slashes and giving the Lambda a bum reference?

1
did you try double-quote your "${application_version}"? - xion
actually, that's what I started with. I noticed that I had ${APPLICATION_VERSION} double quoted and ${S3_AWS_RELEASES_BUCKET} not double quoted, when I saw this error, I removed the double quotes as one of my early tries at fixing this. The quoting (or not quoting) ended up making no difference. - Michael Coxon

1 Answers

1
votes

It's not cloudformation what doing it. The behavior you are seeing is normal behavior.

Generally, When you define the handler as "folder1.folder2.file.handler", it will look for a folder1, then look for folder2 inside that, then look for the file file.py inside. Finally, the file.py is expected to have a function named handler.

I am assuming that your zip file has a top folder called src. In that case, your handler should be defined as src.lambdas.celestial_persist_function.handler since you have already mentioned where your zip file is using the S3Key.

hope this helps.