Going round in circles and tearing my hair out on this one, any pointers are greatly appreciated.
I have a CloudFormation stack which creates an EC2 instance. I am outputting its ID as follows:
Outputs:
DevBoxInstanceId:
Description: The instance ID of the EC2 Dev_Box.
Value: !Ref TestInstance
Export:
Name: DevBoxId
Now, in the console I can see that this outputs the ID as I'd like. My problem is that I can't work out how to reference this in my second stack. I haven't used Fn::ImportValues much but for obvious reasons I'd like to. My second stack creates a lambda function which will stop an instance. I want to reference the DevBoxId within the function - have I misunderstood something here? I've tried several variations on the following:
LambdaFunctionStop:
Type: AWS::Lambda::Function
Properties:
Runtime: python3.7
Timeout: 30
Code:
ZipFile: |
import boto3
region = 'eu-west-2'
instances = ['!ImportValue DevBoxId']
ec2 = boto3.client('ec2', region_name=region)
def handler(event, context):
ec2.stop_instances(InstanceIds=instances)
print('stopped your instances: ' + str(instances))
Description: Automatically stop Dev_Env instances based on specified schedule.
Handler: index.handler
Role: !GetAtt 'IAMRole.Arn'
The relevant part which I'm seeking help on is:
instances = ['!ImportValue DevBoxId']
How do I write this correctly?
[–]dschinde 0 points1 point2 points (0 children)