amazon-cloudformation

How to set tags of the root volume of EC2 instance via CloudFormation

南笙酒味 提交于 2019-12-04 11:57:58
Create EC2 instance using CloudFormation, but the name (tags) of root volume is empty. How to set it using CloudFormation? # ec2-instance.yml (CloudFormation template) MyInstance: Type: "AWS::EC2::Instance" Properties: ImageId: "ami-da9e2cbc" InstanceType: "t2.nano" KeyName: !Ref "KeyPair" Tags: # This is for EC2 instance (not root volume) - Key: "Name" Value: "my-instance" I find "Volumes" and "BlockDeviceMappings" properties but it could not. CloudFormation does not appear to support this currently. However using an instance user data script , you can do this to tag the root volume: apt-get

How to use IAM role to access resources using temporary credentials?

前提是你 提交于 2019-12-04 10:39:27
I'm using AWS IAM roles that allows an instance to have access to certain resources using temporary API credentials (access key, secret key and security token). When I test the temporary credentials using this ruby script, it runs without any problems : require 'rubygems' require 'aws-sdk' AWS.config( :access_key_id => "MY ACCESS KEY GOES HERE", :secret_access_key => "MY SECRET KEY GOES HERE", :session_token => "MY TOKEN GOES HERE") s3 = AWS::S3.new() myfile = s3.buckets['My-Config'].objects["file.sh"] File.open("/tmp/file.sh", "w") do |f| f.write(myfile.read) end But when using command line

aws Lambda created ENI not deleting while deletion of stack

℡╲_俬逩灬. 提交于 2019-12-04 10:36:57
问题 CloudFormation creates Lambda function. When the function is executed an ENI is provisioned automatically by lambda. The ENI seems to be left in existence after function execution for to speed up subsequent function execution. CloudFormation deletes the lambda function. The EN remains behind. When attempting to delete the VPC CloudFormation stack , stack deletion fails as the ENI is using a security group and subnet . in my lambda role the delete permission are there. "Effect": "Allow",

How to use !FindInMap in !Sub | userdata section

假如想象 提交于 2019-12-04 09:23:56
Currently I am converting CFT from JSON to Yaml. Everything works fine until Userdata section.I am having hard time to use any of functions like !Ref or !FindInMap in userdata section. UserData: Fn::Base64: !Sub | #!/bin/bash -v /command {Fn::FindInMap: [ "url", Ref: AWS::Region, Ref: EnvironmentType ] } It would be very helpful, If anyone can share any snippet of code. I've been having fun and games with this as well. Although the documentation says that Fn::FindInMap is supported in Fn::Sub , there's no example of use and I've tried all sorts of combinations of quotes and colons without

CloudFormation — possible to have nested Mappings?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 08:31:32
Is it possible to have nested Mappings in CloudFormation, like the following example? "Mappings" : { "Regions" : { "us-east-1" : { "Environments" : { "dev" : { "ImageId" : "something", "Subnet" : "something" }, "qa" : { "ImageId" : "something", "Subnet" : "something" } } }, "us-west-2" : { "Environments" : { "dev" : { "ImageId" : "something", "Subnet" : "something" }, "qa" : { "ImageId" : "something", "Subnet" : "something" } } } } } When I attempt to do something like this, I get the following error: Template format error: Every Mappings attribute must be a String or a List. If nested

Passing userdata file to AWS Cloudformation stack

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 07:59:04
I have a shell script(userdata file) and wondering is there a CLI command parameter that allows user to launch Cloudformation stack with userdata file? Inside your template, use a CloudFormation parameter for the instance userdata: { "Parameters": { "UserData": { "Type": "String" } }, "Resources": { "Instance": { "Type" : "AWS::EC2::Instance", "Properties" : { "UserData" : { "Ref" : "UserData" }, ... } }, ... } } Assuming you're using a Unix-like command line environment, create your stack like this: aws cloudformation create-stack --stack-name myStack \ --template-body file://myStack.json \ -

Using Ref as the first argument in Fn::Sub intrinsic function

一世执手 提交于 2019-12-04 07:50:50
I experience quite strange issues when compiling the template, where I reference a string parameter in Fn::Sub , while the docs do explicitly say that one can use Ref function inside of Fn::Sub . Here is a piece of template: "Resources": { "LaunchConfiguration": { "Type" : "AWS::AutoScaling::LaunchConfiguration", "Properties" : { "UserData": { "Fn::Base64": { "Fn::Sub": { "Ref": "UserDataParam" } } }, And here is an error I get: Template error: One or more Fn::Sub intrinsic functions don't specify expected arguments. Specify a string as first argument, and an optional second argument to

Enable Lambda function to an S3 bucket using cloudformation

落爺英雄遲暮 提交于 2019-12-04 07:41:35
问题 We are creating an S3 bucket using a CloudFormation template. I would like to associate (Add an event to S3 bucket) a Lambda function whenever a file is added to the S3 bucket. How is it possible through CloudFormation templates. What are the properties which needs to be used in CloudFormation. 回答1: Here's a complete, self-contained CloudFormation template that demonstrates how to trigger a Lambda function whenever a file is added to an S3 bucket: Description: Upload an object to an S3 bucket

aws CAPABILITY_AUTO_EXPAND console web codepipeline with cloudformation

元气小坏坏 提交于 2019-12-04 06:52:40
I am trying to complete a codepipeline with the cloudformation service and this error is generated. It must be said that the separate cloudformation service works well. The complete error is: JobFailed Requires capabilities: [CAPABILITY_AUTO_EXPAND] (Service: AmazonCloudFormation; Status Code: 400; Error Code: InsufficientCapabilitiesException; Request ID: 1a977102-f829-11e8-b5c6-f7cc8454c4d0) The solutions I have is to add the CAPABILITY_AUTO_EXPAND --capabilities parameter but that only applies to CLI and my case is by web console. Ran into the same problem, I could not find a way to do it

How do we access and respond to CloudFormation custom resources using an AWS Lambda function written in Java?

末鹿安然 提交于 2019-12-04 05:45:07
I have am AWS Lambda function written in Java that I would like to use as part of a response to an AWS CloudFormation function. Amazon provides two detailed examples on how to create a CloudFormation custom resource that returns its value based on an AWS Lambda function written in Node.js, however I have been having difficulty translating the Lambda examples into Java. How can we setup our AWS Java function so that it reads the value of the pre-signed S3 URL passed in as a parameter to the Lambda function from CloudFormation and send back our desired response to the waiting CloudFormation