MCPcopy Create free account
hub / github.com/cargo-lambda/cargo-lambda / create

Function create

crates/cargo-lambda-deploy/src/roles.rs:36–122  ·  view source on GitHub ↗
(
    deploy: &Deploy,
    config: &SdkConfig,
    progress: &Progress,
)

Source from the content-addressed store, hash-verified

34}
35
36pub(crate) async fn create(
37 deploy: &Deploy,
38 config: &SdkConfig,
39 progress: &Progress,
40) -> Result<FunctionRole> {
41 progress.set_message("creating execution role");
42
43 let role_name = format!("cargo-lambda-role-{}", uuid::Uuid::new_v4());
44 let client = IamClient::new(config);
45 let sts_client = StsClient::new(config);
46 let identity = sts_client
47 .get_caller_identity()
48 .send()
49 .await
50 .into_diagnostic()
51 .wrap_err("failed to get caller identity")?;
52
53 let mut policy = serde_json::json!({
54 "Version": "2012-10-17",
55 "Statement": [
56 {
57 "Effect": "Allow",
58 "Action": ["sts:AssumeRole"],
59 "Principal": {
60 "Service": "lambda.amazonaws.com"
61 }
62 },
63 {
64 "Effect": "Allow",
65 "Action": ["sts:AssumeRole", "sts:SetSourceIdentity", "sts:TagSession"],
66 "Principal": {
67 "AWS": identity.arn().expect("missing account arn"),
68 }
69 }
70 ]
71 });
72
73 tracing::trace!(policy = ?policy, "creating role with assume policy");
74
75 let role = client
76 .create_role()
77 .role_name(&role_name)
78 .assume_role_policy_document(policy.to_string())
79 .set_tags(deploy.iam_tags())
80 .send()
81 .await
82 .into_diagnostic()
83 .wrap_err("failed to create function role")?
84 .role
85 .expect("missing role information");
86
87 client
88 .attach_role_policy()
89 .role_name(&role_name)
90 .policy_arn(BASIC_LAMBDA_EXECUTION_POLICY)
91 .send()
92 .await
93 .into_diagnostic()

Callers 12

use_zip_in_placeFunction · 0.85
zip_binaryFunction · 0.85
create_projectFunction · 0.85
download_zip_templateFunction · 0.85
upsert_functionFunction · 0.85
test_build_exampleFunction · 0.85
test_deploy_workspaceFunction · 0.85
test_build_zip_workspaceFunction · 0.85
download_exampleFunction · 0.85

Calls 6

newFunction · 0.85
try_assume_roleFunction · 0.85
set_messageMethod · 0.80
iam_tagsMethod · 0.80
arnMethod · 0.80
popMethod · 0.80

Tested by 6

test_build_exampleFunction · 0.68
test_deploy_workspaceFunction · 0.68
test_build_zip_workspaceFunction · 0.68