Erik Asplund
Erik Asplund

Reputation: 833

AWS Cloudformation package wont update code

I have this issue: I have deployed a function with CF that is build with the aws cloudformation package command. The first deployment works perfect. But when it try to update the code nothing happens. This is what I do:

Have anyone else experienced the same? I have tried to rename the CF file, script file and the packaged CF file. But it still get the same result. Does anyone here have an ide on what i may try?

This is how the unpackaged function part of the CF looks like:

  CRFunction:
    Type: AWS::Serverless::Function
    Properties:
      Description: Convert IAM Policy into SCP
      Handler: scpfunction.lambda_handler
      Runtime: python3.9
      Timeout: 30
      MemorySize: 128
      FunctionName: !Sub SCP-Function-${SCPName}
      CodeUri: src/
      Environment:
        Variables:
          SCPName: !Ref SCPName
          Policy: !Ref IAMPolicyToConvertToSCP
          OUs: !Ref OUs
          Description: !Ref Description
      Policies:
        Statement:
          - Effect: Allow
            Action:
              - organizations:CreatePolicy
              - organizations:AttachPolicy
              - organizations:List*
              - iam:get*
            Resource: '*'

Upvotes: 1

Views: 1310

Answers (2)

Erik Asplund
Erik Asplund

Reputation: 833

I got this solved. It was not an issue related to AWS. After restarting VisualStudioCode I got the deployment to work. So it had to do with some local caching or something. Really weird never experienced anything like that before.

Upvotes: 0

Marcin
Marcin

Reputation: 238747

Have anyone else experienced the same?

That's how it works by design. Changes to the source code are not detected. You have to change either Key or Version in your CloudFormation template to deploy the new code.

Update

s3://mybucket/319bd03cb3cc8d50ceb80e52bf51c53c is only your function code, not the template. To update your function using s3://mybucket/319bd03cb3cc8d50ceb80e52bf51c53c you have to use AWS Lambda console's Amazon S3 location:

enter image description here

Upvotes: 2

Related Questions