Sceptre: Inherit Profile in Hook Commands

Created on 1 Apr 2020  路  4Comments  路  Source: Sceptre/sceptre

AWS_PROFILE environment value should be inherited from profile when executing commands from config hooks.

Quick glance at:
https://github.com/Sceptre/sceptre/blob/master/sceptre/hooks/__init__.py#L22

I'd assume you could pass stack.profile value to an AWS_PROFILE env var set in hook cmd subprocess.

Most helpful comment

hey @tahoward does this work?

template_path: <template_name>.yaml
hooks:
  after_create:
    - !cmd "aws --profile {{stack_group_config.profile}} <options>"

All 4 comments

When you create your stack you can assign value to profile. And that should be available as a property on stack. Can you give a code example of what you are trying to do?

Yes, for example if I have a config config/dev/us-west-2/config.yaml populated with:

profile: <profile_name>
region: <aws_region>

I'd expect hook executed in config/dev/us-west-2/<resource>.yaml populated with:

template_path: <template_name>.yaml
hooks:
  after_create:
    - !cmd "aws <options>"

...to execute the AWS CLI command with AWS_PROFILE and AWS_DEFAULT_REGION sub process environment variables set to config's profile and region values respectively.

hey @tahoward does this work?

template_path: <template_name>.yaml
hooks:
  after_create:
    - !cmd "aws --profile {{stack_group_config.profile}} <options>"

came across this issue becaus i stumbled upon the same problem as the thread opener. the workaround provided by @zaro0508 definitely works (at least for me)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gbegher picture gbegher  路  3Comments

n2taylor picture n2taylor  路  7Comments

theseanything picture theseanything  路  4Comments

dalibor-aleksic-atomia picture dalibor-aleksic-atomia  路  4Comments

ivanilves picture ivanilves  路  4Comments