Skip to content

Commit bd8a2c0

Browse files
authored
specify --profile for cli (#874)
* wip to optionally specify aws profile for cli * update documentation * remove extra parameter doc bracket * add new unit tests for profile arg * support profiles in type schema loader
1 parent 89b73d3 commit bd8a2c0

18 files changed

+292
-90
lines changed

doc_source/resource-type-cli-invoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Performs contract tests on the specified handler of a resource type\.
1010
cfn invoke
1111
[--endpoint <value>]
1212
[--function-name <value>]
13+
[--profile <value>]
1314
[--region <value>]
1415
[--max-reinvoke <value>]
1516
action
@@ -30,6 +31,10 @@ The logical Lambda function name in the SAM template\. Alternately, you can also
3031

3132
Default: `TypeFunction`
3233

34+
`--profile <value>`
35+
36+
The AWS profile to use\. If no profile is specified, the client applies credentials specified in the [Boto3 credentials chain](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html)\.
37+
3338
`--region <value>`
3439

3540
The region to configure the client to interact with\.

doc_source/resource-type-cli-submit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The user registering the extension must be able to access the schema handler pac
2222
cfn submit
2323
[--dry-run]
2424
[--endpoint-url <value>]
25+
[--profile <value>]
2526
[--region <value>]
2627
[--role-arn <value>]
2728
[--no-role]
@@ -42,6 +43,10 @@ The CloudFormation endpoint to use\.
4243

4344
The AWS Region in which to register the extension\. If no Region is specified, the extension is registered in the default region\.
4445

46+
`--profile <value>`
47+
48+
The AWS profile to use\. If no profile is specified, the CloudFormation CLI applies credentials specified in the [Boto3 credentials chain](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html)\.
49+
4550
`--role-arn <value>`
4651

4752
A specific IAM role to use when invoking handler operations\.

doc_source/resource-type-cli-test.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Performs contract tests on the handlers of a resource type\.
1010
cfn test
1111
[--endpoint <value>]
1212
[--function-name <value>]
13+
[--profile <value>]
1314
[--region <value>]
1415
[--role-arn <value>]
1516
```
@@ -28,6 +29,10 @@ The logical Lambda function name in the SAM template\. Alternately, you can also
2829

2930
Default: `TestEntrypoint`
3031

32+
`--profile <value>`
33+
34+
The AWS profile to use\. If no profile is specified, the contract tests apply credentials specified in the [Boto3 credentials chain](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html)\.
35+
3136
`--region <value>`
3237

3338
The region to use for temporary credentials\.

src/rpdk/core/boto_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
LOWER_CAMEL_CRED_KEYS = ("accessKeyId", "secretAccessKey", "sessionToken")
1515

1616

17-
def create_sdk_session(region_name=None):
17+
def create_sdk_session(region_name=None, profile_name=None):
1818
def _known_error(msg):
1919
raise CLIMisconfiguredError(
2020
msg + ". Please ensure your AWS CLI is configured correctly: "
2121
"https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html"
2222
)
2323

24-
session = Boto3Session(region_name=region_name)
24+
session = Boto3Session(profile_name=profile_name, region_name=region_name)
2525

2626
if session.region_name is None:
2727
_known_error("No region specified")

src/rpdk/core/contract/hook_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ def __init__(
5959
docker_image=None,
6060
executable_entrypoint=None,
6161
target_info=None,
62-
): # pylint: disable=too-many-arguments
62+
profile=None,
63+
): # pylint: disable=too-many-arguments,too-many-locals
6364
self._schema = schema
64-
self._session = create_sdk_session(region)
65+
self._session = create_sdk_session(region, profile)
6566
self._role_arn = role_arn
6667
self._type_name = type_name
6768
self._log_group_name = log_group_name

src/rpdk/core/contract/resource_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ def __init__(
169169
log_role_arn=None,
170170
docker_image=None,
171171
executable_entrypoint=None,
172+
profile=None,
172173
): # pylint: disable=too-many-arguments
173-
self._session = create_sdk_session(region)
174+
self._session = create_sdk_session(region, profile)
174175
self._role_arn = role_arn
175176
self._type_name = type_name
176177
self._log_group_name = log_group_name

src/rpdk/core/generate.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ def generate(args):
1313
project = Project()
1414
project.load()
1515
project.generate(
16-
args.endpoint_url, args.region, args.local_only, args.target_schemas
16+
args.endpoint_url,
17+
args.region,
18+
args.local_only,
19+
args.target_schemas,
20+
args.profile,
1721
)
1822
project.generate_docs()
1923

@@ -33,3 +37,4 @@ def setup_subparser(subparsers, parents):
3337
parser.add_argument(
3438
"--target-schemas", help="Path to target schemas.", nargs="*", default=[]
3539
)
40+
parser.add_argument("--profile", help="AWS profile to use.")

src/rpdk/core/hook/init_hook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def init_hook(args, project):
3131
}
3232

3333
project.init_hook(type_name, language, settings)
34-
project.generate(args.endpoint_url, args.region, args.target_schemas)
34+
project.generate(args.endpoint_url, args.region, args.target_schemas, args.profile)
3535
project.generate_docs()
3636

3737

src/rpdk/core/init.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,5 @@ def setup_subparser(subparsers, parents):
199199
default=[],
200200
type=lambda s: [i.strip() for i in s.split(",")],
201201
)
202+
203+
parser.add_argument("--profile", help="AWS profile to use.")

src/rpdk/core/invoke.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def get_contract_client(args, project):
5858
{},
5959
executable_entrypoint=project.executable_entrypoint,
6060
docker_image=args.docker_image,
61+
profile=args.profile,
6162
)
6263

6364
return ResourceClient(
@@ -68,6 +69,7 @@ def get_contract_client(args, project):
6869
{},
6970
executable_entrypoint=project.executable_entrypoint,
7071
docker_image=args.docker_image,
72+
profile=args.profile,
7173
)
7274

7375

0 commit comments

Comments
 (0)