0

I have a very simple Jenkins job that builds and then deploys a step function to AWS. I have been able to build and deploy from my desktop using the SAM cli no problem. However, when I set up jenkins to do it I get the following error:

ERROR: Build step failed with exception com.amazonaws.waiters.WaiterUnrecoverableException: Resource never entered the desired state as it failed.

The stack gets created in AWS and stays in REVIEW_IN_PROGRESS. I'm assuming that the 'Waiter' is waiting for the stack to enter another state. I found this but it doesn't help very much.

Through the SAM CLI I can package and deploy just fine with

sam package --output-template-file packaged.yaml --s3-bucket thebucketofjesse
sam deploy --template-file packaged.yaml --stack-name jesse-stack-6 --capabilities CAPABILITY_IAM --region us-west-1

EDIT

I think I may have discovered the cause of this issue. I stopped using the SAM plugin and instead created a batch script to run the SAM commands manually. Everything worked except for some reason 'sam package' isn't adding the S3 uri to the yaml template output. So when it runs 'sam deploy' it looks at the output template and expects an S3 uri. It then fails and leaves the stack in REVIEW_IN_PROGRESS state.

When I run the above commands in the cli manually it will upload my state-machine.yaml file to S3 and the resulting packaged.yaml cloudformation template will have the S3 uri.

template.yaml

template.yaml

packaged.yaml packaged.yaml

When I run the sam commands in jenkins the S3 uri is not in packaged.yaml

user3236794
  • 578
  • 1
  • 6
  • 16

1 Answers1

0

I figured it out. So there seems to be an issue with the sam package command.

In my template.yaml file I am specifying the definition of my step function in an external file called state-machine.yaml (If you don't know how to do that go here). In the template.yaml file it looks like this

Resources:
  ClosedCaptionStateMachine:
    Type: AWS::StepFunctions::StateMachine
    Properties:
      RoleArn:
        Fn::GetAtt:
        - ClosedCaptionStateMachineRole
        - Arn
      Fn::Transform:
        Name: AWS::Include
        Parameters:            
          Location: 'state-machine.yaml'

When I run sam package it is supposed to upload the state-machine.yaml file to an S3 bucket and then insert the S3 uri into the resulting yaml output file which I named packaged.yaml. It looks like this

Resources:
  ClosedCaptionStateMachine:
    Type: AWS::StepFunctions::StateMachine
    Properties:
      RoleArn:
        Fn::GetAtt:
        - ClosedCaptionStateMachineRole
        - Arn
      Fn::Transform:
        Name: AWS::Include
        Parameters:
          Location: s3://thebucketofjesse/ba638c2815c6a4d4ad93c5bb5e3c4f32

However, for some reason it was not putting the S3 uri in packaged.yaml. Instead it kept it as state-machine.yaml. So when I ran sam deploy it would look for the S3 uri but not find it.

So what's the fix?

Well I discovered, purely by chance, that if you run sam package from outside the directory that template.yaml is located in and use full paths, it doesn't put the S3 uri in packaged.yaml. So you have to run sam package from the directory that template.yaml is located in and use relative paths.

user3236794
  • 578
  • 1
  • 6
  • 16